import javax.swing.*; import java.awt.*; import java.awt.event.*; public class HandleButtonClicks extends JFrame implements ActionListener { public void setupMyFrame() { this.setSize(400, 400); this.setTitle("Java Frame"); Container p = this.getContentPane(); p.setLayout(new FlowLayout()); JButton button1 = new JButton("Quit!"); JButton button2 = new JButton("Don't Quit!"); button1.addActionListener(this); button2.addActionListener(this); p.add(button1); p.add(button2); this.setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equalsIgnoreCase("Quit!")) System.exit(0); else System.out.println("I am not quitting!"); } public static void main(String[] args) { HandleButtonClicks frame = new HandleButtonClicks(); frame.setupMyFrame(); } }