001: /*
002: * @(#)DemoFrame.java 1.6 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 personal;
027:
028: import java.awt.*;
029: import java.awt.event.*;
030: import java.util.ArrayList;
031:
032: public class DemoFrame extends basis.DemoFrame {
033: Dialog dialog;
034: FileDialog fileDialog;
035:
036: static {
037: DemoFrame.className = "personal.DemoFrame";
038: DemoFrame.title = "J2ME Personal";
039: demos.add("personal.demos.WidgetDemo");
040: }
041:
042: public static void main(String[] args) throws Exception {
043: basis.DemoFrame.parse(args);
044: Frame frame = new DemoFrame(demos, size);
045: frame.setVisible(true);
046: }
047:
048: public DemoFrame(ArrayList demos, Dimension size) throws Exception {
049: super (demos, size);
050: MenuBar menuBar = new MenuBar();
051: Menu menu = new Menu("Menu");
052: ActionListener listener = new ActionListener() {
053: public void actionPerformed(ActionEvent e) {
054: MenuItem mi = (MenuItem) e.getSource();
055: builder.showDemo(mi.getLabel());
056: }
057: };
058: if (demos.contains("personal.demos.WidgetDemo")) {
059: if (demos.size() > 1) {
060: for (int i = 0; i < demos.size(); i++) {
061: String label = (String) demos.get(i);
062: label = label.substring(label.lastIndexOf(".") + 1,
063: label.lastIndexOf("Demo"));
064: MenuItem mi = new MenuItem(label);
065: menu.add(mi);
066: mi.addActionListener(listener);
067: }
068: }
069: MenuItem dialogMenuItem = new MenuItem("Dialog ");
070: dialogMenuItem.addActionListener(new ActionListener() {
071: public void actionPerformed(ActionEvent ae) {
072: if (dialog == null) {
073: dialog = new AboutDialog(DemoFrame.this ,
074: "Dialog", true);
075: Toolkit toolkit = getToolkit();
076: Dimension screen = toolkit.getScreenSize();
077: Dimension dim = dialog.getSize();
078: dialog.setLocation(
079: (screen.width - dim.width) / 2,
080: (screen.height - dim.height) / 3);
081: }
082: dialog.setVisible(true);
083: }
084: });
085: MenuItem fileMenuItem = new MenuItem("File dialog");
086: fileMenuItem.addActionListener(new ActionListener() {
087: public void actionPerformed(ActionEvent ae) {
088: if (fileDialog == null) {
089: fileDialog = new FileDialog(DemoFrame.this ,
090: "FileDialog");
091: }
092: fileDialog.setVisible(true);
093: }
094: });
095: MenuShortcut ms = new MenuShortcut(KeyEvent.VK_E);
096: MenuItem exitMenuItem = new MenuItem("Exit", ms);
097: exitMenuItem.addActionListener(new ActionListener() {
098: public void actionPerformed(ActionEvent ae) {
099: System.exit(0);
100: }
101: });
102: menu.addSeparator();
103: menu.add(new CheckboxMenuItem("Checkbox "));
104: menu.add(dialogMenuItem);
105: menu.add(fileMenuItem);
106: menu.add(exitMenuItem);
107: menuBar.add(menu);
108: setMenuBar(menuBar);
109: // To prevent widgets displaying on top of other demos...
110: if (demos.size() > 1) {
111: builder.showDemo("Widget");
112: builder.showDemo("Graphics");
113: }
114: }
115: }
116:
117: public class AboutDialog extends Dialog {
118: AboutDialog(Frame owner, String title, boolean modal) {
119: super (owner, title, modal);
120: Label label = new Label("This is a dialog");
121: add("Center", label);
122: Button button = new Button("Close");
123: button.addActionListener(new ActionListener() {
124: public void actionPerformed(ActionEvent ae) {
125: AboutDialog.this .setVisible(false);
126: }
127: });
128: add("South", button);
129: pack();
130: }
131: }
132: }
|