Import java.awt. *;
Import java.awt.event. *;
Public Class Dialogwindow Extends Frame Implements ActionListener {
Boolean in Annapplet = true; // shop be privat
Private SimpleDialog Dialog;
Private textarea textarea;
String newline;
Public dialogwindow () {
Textarea = New Textarea (5, 40);
TextArea.setedITable (FALSE);
Add ("Center", Textarea;
Button Button = New Button ("Click to Bring Up Dialog";
Button.addActionListener (this);
Panel panel = new panel ();
Panel.Add (Button);
Add ("South", Panel;
AddWindowListener (New Windowadapter () {
Public void windowClosing (WindowEvent E) {
IF (in AnApplet) {
Setvisible (false);
Dispose ();
} else {
System.exit (0);
}
}
});
NEWLINE = System.getProperty ("line.separator");
}
Public void actionPerformed (ACTIONEvent Event) {
IF (dialog == null) {
Dialog = New SimpleDialog (this, "a Simple Dialog");
}
Dialog.setVisible (TRUE);
}
Public void setText (string text) {
Textarea.Append (Text Newline);
}
Public static void main (string args []) {
Dialogwindow window = new dialogwindow ();
WINDOW.INANAPPLET = FALSE;
Window.SetTitle ("Dialogwindow Application");
Window.pack ();
WINDOW.SETVISIBLE (TRUE);
}
}
Class SimpleDialog Extends Dialog IMPLEments ActionListener {
Textfield Field;
Dialogwindow parent;
Button setButton;
SimpleDialog (Frame DW, String Title) {
Super (DW, Title, False);
Parent = (Dialogwindow) DW;
// CREATE MIDDLE Section.
Panel p1 = new panel ();
Label label = new label ("Enter Random Text Here:");
P1.Add (label);
Field = New TextField (40);
Field.AddActionListener (this);
P1.Add (Field);
Add ("Center", P1);
// Create bottom row.panel p2 = new panel ();
P2.setLayout (new flowLayout (flowlayout.right);
Button B = New Button ("CANCEL");
B. ADDACTIONLISTENER (THIS);
SetButton = New Button ("SET");
SetButton.AddActionListener (this);
P2.Add (b);
P2.Add (setButton);
Add ("South", P2);
// Initialize this dialog to its preferred size.
Pack ();
}
Public void actionPerformed (ACTIONEvent Event) {
Object Source = event.getsource ();
IF (Source == SetButton) | (Source == Field)) {
Parent.setText (Field.getText ());
}
Field.SelectAll ();
Setvisible (false);
}
}