1 import java.awt.*;
2 import javax.swing.*;
3
4 /**
5
6
7
8
9 */
10 public class CommandTester
11 {
12 public static void main(String[] args)
13 {
14 JFrame frame = new JFrame();
15 JMenuBar bar = new JMenuBar();
16 frame.setJMenuBar(bar);
17 JMenu menu = new JMenu("Say");
18 bar.add(menu);
19 JToolBar toolBar = new JToolBar();
20 frame.add(toolBar, BorderLayout.NORTH);
21 JTextArea textArea = new JTextArea(10, 40);
22 frame.add(textArea, BorderLayout.CENTER);
23
24 GreetingAction helloAction = new GreetingAction(
25 "Hello, World", textArea);
26 helloAction.putValue(Action.NAME, "Hello");
27 helloAction.putValue(Action.SMALL_ICON,
28 new ImageIcon("hello.png"));
29
30 GreetingAction goodbyeAction = new GreetingAction(
31 "Goodbye, World", textArea);
32 goodbyeAction.putValue(Action.NAME, "Goodbye");
33 goodbyeAction.putValue(Action.SMALL_ICON,
34 new ImageIcon("goodbye.png"));
35
36 helloAction.setOpposite(goodbyeAction);
37 goodbyeAction.setOpposite(helloAction);
38 goodbyeAction.setEnabled(false);
39
40 menu.add(helloAction);
41 menu.add(goodbyeAction);
42
43 toolBar.add(helloAction);
44 toolBar.add(goodbyeAction);
45
46 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
47 frame.pack();
48 frame.setVisible(true);
49 }
50 }