package util; import java.awt.*; import java.awt.event.*; public class SimpleInputDialog extends Dialog { public SimpleInputDialog (String prompt) { this(prompt, new TextField(100)); } public String getInput () { return myString; } public int getValue () { try { return Integer.parseInt(myString); } catch (NumberFormatException e) { return 0; } } protected SimpleInputDialog (String prompt, TextField inputField) { super(new Frame(), prompt, true); // make the dialog modal myString = null; myInputField = inputField; Panel buttonPanel = new Panel(); Button ok = new Button("OK"); Button cancel = new Button("Cancel"); buttonPanel.add(ok); buttonPanel.add(cancel); myInputField.addActionListener(new ProcessOk()); ok.addActionListener(new ProcessOk()); cancel.addActionListener( new ActionListener() { public void actionPerformed (ActionEvent e) { myString = null; SimpleInputDialog.this.setVisible(false); } }); setLayout(new BorderLayout()); add("North", myInputField); add("South", buttonPanel); } private String myString; private TextField myInputField; class ProcessOk implements ActionListener { public void actionPerformed (ActionEvent e) { myString = myInputField.getText(); SimpleInputDialog.this.setVisible(false); } } }