CHAPTER 7 ■ WRITING A USER INTERFACE
panel.add(sayButton);
frame.add(panel);
}
private void createAndShowGUI() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addMenu(frame);
arrangeComponents(frame);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingDemo swingDemo = new SwingDemo();
swingDemo.createAndShowGUI();
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Exit")) {
System.exit(0);
}
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.getSource() == sayButton) {
JOptionPane.showMessageDialog(frame, sayText.getText(),
"You said", JOptionPane.PLAIN_MESSAGE);
}
}
}