Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00036 package gui;
00037
00038 import java.lang.*;
00039 import java.awt.*;
00040 import java.io.*;
00041 import java.awt.event.*;
00042
00043 public class InputDialog extends Dialog
00044 {
00045
00046
00047 protected TextField textHolder;
00048 protected String result = null;
00049
00050
00051
00052 public InputDialog(Frame dw, String label)
00053 {
00054 super(dw, "Dialog", true);
00055
00056 Panel p1 = new Panel();
00057 p1.add(new Label(label));
00058
00059 Panel p2 = new Panel();
00060 textHolder = new TextField(label.length());
00061 p2.add(textHolder);
00062
00063
00064
00065 Panel p3 = new Panel();
00066 Button okButton = new Button("Ok");
00067 okButton.addActionListener(new ActionListener()
00068 { public void actionPerformed(ActionEvent e)
00069 { okPressed();}});
00070 Button cancelButton = new Button("Cancel");
00071 cancelButton.addActionListener(new ActionListener()
00072 { public void
00073 actionPerformed(ActionEvent e)
00074 { cancelPressed();}});
00075 p3.add(okButton);
00076 p3.add(cancelButton);
00077
00078 add("North",p1);
00079 add("Center",p2);
00080 add("South",p3);
00081
00082
00083 pack();
00084 setLocation(defaultLocation());
00085
00086
00087
00088
00089
00090 }
00091
00092 public Point defaultLocation()
00093 {
00094 Point newLoc;
00095 Toolkit tk = Toolkit.getDefaultToolkit();
00096 Dimension screenSize = tk.getScreenSize();
00097 int w = this.getBounds().width;
00098 int h = this.getBounds().height;
00099 if ((w < screenSize.width) && (h < screenSize.height)) {
00100 newLoc = new Point((screenSize.width-w)/2,
00101 (screenSize.height-h)/2);
00102 } else {
00103 newLoc = new Point(0,0);
00104 }
00105 return newLoc;
00106 }
00107
00108
00109
00110 public void okPressed()
00111 {
00112 result = textHolder.getText();
00113 closeDialog();
00114 }
00115
00116 public void cancelPressed()
00117 {
00118 result = null;
00119 closeDialog();
00120 }
00121
00122 public void closeDialog()
00123 {
00124 setVisible(false);
00125 dispose();
00126 }
00127
00128
00129
00130 public String result()
00131 {
00132 return result;
00133 }
00134
00135 public void setInitialValue(String txt)
00136 {
00137 textHolder.setText(txt);
00138 }
00139
00140 }
00141