Construct the object including its GUI
super("JFrameDemo");
getContentPane().add(quitButton = new JButton("Exit"));
// These "action handlers" will be explained later in the chapter.
quitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
dispose();
System.exit(0);
}
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible(false);
dispose();
System.exit(0);
}
});
pack();