import java.util.* ; import java.io.* ; import java.awt.* ; import java.awt.event.* ; import javax.swing.* ; import javax.swing.event.* ; class TerminationListener implements WindowListener { public void windowActivated(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowClosing(WindowEvent e) { System.exit(0) ; } public void windowDeactivated(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowOpened(WindowEvent e) {} } class DialoguePanel extends JPanel implements ActionListener { public DialoguePanel() { display = new JTextField(20) ; display.setEditable(false) ; add(display) ; JButton button = new JButton("change") ; button.addActionListener(this) ; add(button) ; } public void actionPerformed(ActionEvent evt) { String text = JOptionPane.showInputDialog(this, "Input new text", "Change Displayed Text", JOptionPane.QUESTION_MESSAGE) ; if(text != null) display.setText(text) ; } private JTextField display ; } public class DialogueTest { public static void main(String [] args) { JFrame frame = new JFrame() ; frame.setTitle("Dialogue") ; frame.setSize(450, 300) ; frame.addWindowListener(new TerminationListener()) ; frame.getContentPane().add(new DialoguePanel()) ; frame.setVisible(true) ; } }