import java.awt.*; import javax.swing.*; import java.awt.event.*; public class ModalDialog { public ModalDialog () { final JFrame frame = new JFrame("Event Test"); Container content = frame.getContentPane(); content.setLayout(new FlowLayout()); frame.setSize(300,300); JButton msgButton = new JButton("Button 1"); content.add(msgButton); msgButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { System.out.println("I've been pressed!"); } }); JButton dlgButton = new JButton("Button 2"); content.add(dlgButton); dlgButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JOptionPane.showMessageDialog(frame, "You cannot press Button 1."); } }); frame.setVisible(true); } public static void main(String[] args) { new ModalDialog(); } }