home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-09-17 | 1.4 KB | 74 lines |
- import java.applet.*;
- import java.awt.*;
-
- public class EX16C extends Applet
- {
- protected InputDialog IDialog;
- protected TextField MyField = new TextField(20);
-
- public void SetMyFieldText(String str)
- {
- MyField.setText(str);
- }
-
- public void init()
- {
- add(new Button("Set Text"));
- add(MyField);
-
- // set up the frame for the dialog
- Frame frame = new Frame();
- frame.resize(250, 100);
- IDialog = new InputDialog(frame, this);
- }
-
- public boolean action(Event evt, Object obj)
- {
- boolean result = false; // asume no action
-
- if ("Set Text".equals(obj)) {
- IDialog.show();
- result = true;
- }
-
- return result;
- }
- }
-
- class InputDialog extends Dialog
- {
- protected TextField InputText;
- protected EX16C aplt;
-
- public InputDialog(Frame parent, EX16C aplt)
- {
- super(parent, "Input into my field please...", true);
-
- this.aplt = aplt;
-
- InputText = new TextField();
- add("North", InputText);
-
- Panel p = new Panel();
- p.add(new Button("OK"));
- p.add(new Button("Cancel"));
- add("South", p);
-
- pack();
- resize(250, 100);
- }
-
- public boolean action(Event evt, Object arg)
- {
- boolean result = false; // asume no action
-
- if ("OK".equals(evt.arg)) {
- aplt.SetMyFieldText(InputText.getText());
- dispose(); // close the dialog
- }
- if ("Cancel".equals(evt.arg))
- dispose(); // close the dialog
-
- return result;
- }
- }