home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-06-13 | 3.7 KB | 156 lines |
- // DialogWindow - pop up the dialog box created by the
- // ResourceWizard and wait for the user to enter
- // OK. once he or she does, read the data out of
- // the dialog box, close the dialog box, and
- // display the data in the applet window
- import java.applet.*;
- import java.awt.*;
- import AutoDialog;
-
- public class DialogWindow extends Applet
- {
-
- // the extra frame attached to the applet
- private OurFrame m_frame = null;
-
- public DialogWindow()
- {
- // TODO: Add Constructor code here
- }
-
- public String getAppletInfo()
- {
- return "Name: DialogWindow\r\n" +
- "Author: Stephan R. Davis\r\n" +
- "Created for Learn Java Now";
- }
-
-
- public void init()
- {
- resize(320, 240);
-
- // TODO: Place Addition Initialization code here
- // Create one of our dialog box frames
- m_frame = new OurFrame(this);
- }
-
- public void destroy()
- {
- // TODO: Place applet cleanup code here
- }
-
- public void paint(Graphics g)
- {
- DialogData data = m_frame.getData();
- if (data != null)
- {
- g.drawString(data.toString(), 10, 20);
- }
- }
-
- public void start()
- {
- // TODO: Place additional applet Start code here
- }
-
- public void stop()
- {
- }
-
-
-
-
- // TODO: Place additional applet Code here
-
- }
-
- class OurFrame extends Frame
- {
- // child dialog box
- private AutoDialog m_autodialog = null;
-
- // parent applet
- private Applet m_parent = null;
-
- // data contained in dialog box
- private DialogData m_data = null;
-
- public OurFrame(Applet parent)
- {
- super("Auto Dialog");
-
- m_parent = parent;
-
- // be sure to set a font (the size is unimportant
- // because it will be changed by the AutoDialog class)
- setFont(new Font("Arial", Font.PLAIN, 12));
-
- // now create the AutoDialog and let it add the
- // components to our frame
- m_autodialog = new AutoDialog(this);
- m_autodialog.CreateControls();
-
- show();
- }
-
- public boolean action(Event event, Object obj)
- {
- // if this is our button...
- Object target = event.target;
- if (target instanceof Button)
- {
- Button button = (Button)target;
- String buttonLabel = button.getLabel();
- if (buttonLabel.compareTo("OK") == 0)
- {
- // ...get the data from the dialog box...
- String sFirstName=m_autodialog.IDC_EDIT1.getText();
- String sLastName =m_autodialog.IDC_EDIT2.getText();
- boolean bMarried =
- m_autodialog.IDC_CHECK1.getState();
-
- // ...create a DialogData object...
- m_data = new DialogData(sFirstName,
- sLastName,
- bMarried);
-
- // ...and force the applet to output the data
- m_parent.repaint();
- }
-
- // hide the dialog box if either button is pressed
- hide();
- return true;
- }
- return false;
- }
-
- public DialogData getData()
- {
- return m_data;
- }
- }
-
- class DialogData
- {
- private String m_sFirstName;
- private String m_sLastName;
- private boolean m_bMarried;
-
- public DialogData(String sFN, String sLN, boolean bM)
- {
- m_sFirstName = sFN;
- m_sLastName = sLN;
- m_bMarried = bM;
- }
-
- public String toString()
- {
- String s;
- s = m_sFirstName + " " + m_sLastName + " ";
- s += m_bMarried ? "(married)" : "(single)";
- return s;
- }
- }
-