home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-03-08 | 2.1 KB | 101 lines |
- import java.awt.*;
- import java.applet.*;
-
- public class DialogApplet2 extends Applet
- {
- DialogFrame2 frame;
- Button button;
-
- public void init()
- {
- frame = new DialogFrame2("Dialog 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 DialogFrame2 extends Frame
- {
- MenuBar menuBar;
- Dialog dialog;
- TextField textField;
- String str;
-
- DialogFrame2(String title)
- {
- super(title);
-
- menuBar = new MenuBar();
- setMenuBar(menuBar);
- Menu menu = new Menu("Test");
- menuBar.add(menu);
- MenuItem item = new MenuItem("Dialog box");
- menu.add(item);
-
- str = "";
- }
-
- public void paint(Graphics g)
- {
- resize(300, 250);
-
- g.drawString("THE TEXT YOU ENTERED IS:", 70, 50);
- g.drawString(str, 70, 70);
- }
-
- public boolean action(Event evt, Object arg)
- {
- if (evt.target instanceof MenuItem)
- {
- if (arg == "Dialog box")
- ShowDialogBox();
- }
- else if (evt.target instanceof Button)
- {
- dialog.hide();
- if (arg == "OK")
- {
- str = textField.getText();
- repaint();
- }
- }
-
- return true;
- }
-
- protected void ShowDialogBox()
- {
- dialog = new Dialog(this, "Test Dialog", true);
- FlowLayout layout = new FlowLayout();
- dialog.setLayout(layout);
-
- textField = new TextField("", 30);
- dialog.add(textField);
- Button button = new Button("OK");
- dialog.add(button);
- button = new Button("Cancel");
- dialog.add(button);
-
- dialog.show();
- dialog.resize(220, 120);
- }
- }
-