import javax.swing.*; import java.awt.*; import java.awt.event.*; public class WarningDialog extends JDialog implements ActionListener { private JTextField warningField = new JTextField(20); private JButton ok = new JButton("OK"); private JPanel p = new JPanel(); public WarningDialog(JFrame owner, String warning) { super(owner, true); // must be the first statement in constructor // "true" provides "modal dialog feature" warningField.setText(warning); p.add(warningField); ok.addActionListener(this); p.add(ok); getContentPane().add(p); // not really necessary here addWindowListener( new WindowAdapter() { /* public void windowClosing(WindowEvent e) { setVisible(false); dispose(); } */ }); setTitle(" Warning"); setSize(300,100); setLocation(150,150); } // WarningDialog() //the Dialog is closed only by pushing the Ok Button public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command.equals("OK")) { setVisible(false); } } //actionPerformed } // WarningDialog