home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-03-06 | 1.9 KB | 90 lines |
- import java.awt.*;
- import java.applet.*;
-
- public class MenuBarApplet extends Applet
- {
- MenuBarFrame frame;
- Button button;
-
- public void init()
- {
- frame = new MenuBarFrame("MenuBar Window");
-
- button = new Button("Show Window");
- add(button);
- }
-
- public boolean action(Event evt, Object arg)
- {
- boolean visible = frame.isShowing();
- if (visible)
- {
- frame.hide();
- button.setLabel("Show Window");
- }
- else
- {
- frame.show();
- button.setLabel("Hide Window");
- }
-
- return true;
- }
- }
-
- class MenuBarFrame extends Frame
- {
- MenuBar menuBar;
- String str;
-
- MenuBarFrame(String title)
- {
- super(title);
- menuBar = new MenuBar();
- setMenuBar(menuBar);
-
- Menu menu = new Menu("Test");
- menuBar.add(menu);
-
- MenuItem item = new MenuItem("Command 1");
- menu.add(item);
- item = new MenuItem("Command 2");
- menu.add(item);
-
- item = new MenuItem("-");
- menu.add(item);
-
- CheckboxMenuItem checkItem =
- new CheckboxMenuItem("Check");
- menu.add(checkItem);
-
- str = "";
- Font font = new Font("TimesRoman", Font.BOLD, 20);
- setFont(font);
- }
-
- public void paint(Graphics g)
- {
- resize(300, 250);
- g.drawString(str, 20, 100);
- }
-
- public boolean action(Event evt, Object arg)
- {
- if (evt.target instanceof MenuItem)
- {
- if (arg == "Command 1")
- str = "You selected Command 1";
- else if (arg == "Command 2")
- str = "You selected Command 2";
- else if (arg == "Check")
- str = "You selected the Check item";
-
- repaint();
- return true;
- }
- else
- return false;
- }
- }
-