001: /*
002: * @(#)DemoFrame.java 1.5 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026: package basis;
027:
028: import java.awt.*;
029: import java.awt.event.*;
030: import java.util.ArrayList;
031:
032: public class DemoFrame extends Frame {
033: protected static final int DEFAULT_WIDTH = 240;
034: protected static final int DEFAULT_HEIGHT = 320;
035: protected static String className = "basis.DemoFrame";
036: protected static String title = "J2ME Basis";
037: protected static ArrayList demos = new ArrayList();
038: protected static Dimension size;
039: protected Builder builder;
040:
041: static {
042: demos.add("basis.demos.GraphicsDemo");
043: demos.add("basis.demos.FontDemo");
044: demos.add("basis.demos.EventDemo");
045: demos.add("basis.demos.MiscDemo");
046: demos.add("basis.demos.GameDemo");
047: }
048:
049: public static void main(String[] args) throws Exception {
050: parse(args);
051: Frame frame = new DemoFrame(demos, size);
052: frame.setVisible(true);
053: }
054:
055: protected static void parse(String[] args) {
056: int width = DEFAULT_WIDTH;
057: int height = DEFAULT_HEIGHT;
058: if (args.length > 0) {
059: for (int i = 0; i < args.length; i++) {
060: if (args[i].equals("-d")) {
061: demos = new ArrayList();
062: demos.add(args[++i]);
063: continue;
064: }
065: if (args[i].equals("-w")) {
066: try {
067: width = Integer.parseInt(args[++i]);
068: } catch (NumberFormatException nfe) {
069: usage();
070: System.out.println("Invalid width: " + args[i]);
071: System.out.println("");
072: System.exit(1);
073: }
074: continue;
075: }
076: if (args[i].equals("-h")) {
077: try {
078: height = Integer.parseInt(args[++i]);
079: } catch (NumberFormatException nfe) {
080: usage();
081: System.out
082: .println("Invalid height: " + args[i]);
083: System.out.println("");
084: System.exit(1);
085: }
086: continue;
087: }
088: usage();
089: System.exit(1);
090: }
091: }
092: size = new Dimension(width, height);
093: }
094:
095: protected static void usage() {
096: System.out.println("");
097: System.out.println("USAGE:");
098: System.out.println(" cvm " + className
099: + " [-d demo] [-w width] [-h height]");
100: System.out.println("");
101: System.out.println("WHERE:");
102: System.out
103: .println(" demo = Full package name of specific demo");
104: System.out.println(" width = Width of demo in pixels");
105: System.out.println(" height = Height of demo in pixels");
106: System.out.println("");
107: }
108:
109: public DemoFrame(ArrayList demos, Dimension size) throws Exception {
110: builder = new Builder(demos);
111: builder.build(this );
112: pack();
113: setSize(size);
114: Toolkit toolkit = getToolkit();
115: Dimension screen = toolkit.getScreenSize();
116: setLocation((screen.width - size.width) / 2,
117: (screen.height - size.height) / 3);
118: setTitle(title);
119: addWindowListener(new WindowAdapter() {
120: public void windowClosing(WindowEvent e) {
121: System.exit(0);
122: }
123: });
124: }
125: }
|