// InputForm for multi_window_example application import java.io.*; // need this to do files import java.awt.*; // needed to get "Container" class below import java.awt.event.*; // event processing requirements import javax.swing.*; // we will use Swing... class InputForm extends JDialog implements ActionListener { final static int CANCELLED = 0; final static int OKAYED = 1; multi_window_example app; JButton ok, cancel; JTextField tf_name, tf_ssn, tf_age; int status = 0; InputForm (multi_window_example f) { // Calling the superclass constructor // first parameter is the parent window // second parameter is the title of the window // third is whether to make the dialog MODAL super(f, "Input Data:", true); setSize(120,100); setLocation(220,220); ok = new JButton("OK"); cancel = new JButton("Cancel"); tf_name = new JTextField(15); tf_ssn = new JTextField(15); tf_age = new JTextField(15); Container c = getContentPane(); c.setLayout(new GridLayout(4, 2)); c.add(new JLabel("Name:")); c.add(tf_name); c.add(new JLabel("SSN:")); c.add(tf_ssn); c.add(new JLabel("Age:")); c.add(tf_age); c.add(ok); c.add(cancel); ok.addActionListener(this); cancel.addActionListener(this); } String getStudentName() { return tf_name.getText(); } String getSSN() { return tf_ssn.getText(); } int getAge() { return Integer.parseInt(tf_age.getText()); } int getStatus() { return status; } public void actionPerformed (ActionEvent a) { if (a.getSource() == ok) { status = OKAYED; setVisible(false); } else if (a.getSource() == cancel) { int val = JOptionPane.showConfirmDialog (this, "Do you really want to cancel?", "Confirmation", JOptionPane.YES_NO_OPTION); if (val == 0) { status = CANCELLED; setVisible(false); } } } }