1 import java.awt.event.*;
2 import javax.swing.*;
3
4 /**
5
6
7
8 */
9 public class GreetingAction extends AbstractAction
10 {
11 /**
12
13 @param greeting
14 @param textArea
15 */
16 public GreetingAction(String greeting, JTextArea textArea)
17 {
18 this.greeting = greeting;
19 this.textArea = textArea;
20 }
21
22 /**
23
24 @param action
25
26 */
27 public void setOpposite(Action action)
28 {
29 oppositeAction = action;
30 }
31
32 public void actionPerformed(ActionEvent event)
33 {
34 textArea.append(greeting);
35 textArea.append("\n");
36 if (oppositeAction != null)
37 {
38 setEnabled(false);
39 oppositeAction.setEnabled(true);
40 }
41 }
42
43 private String greeting;
44 private JTextArea textArea;
45 private Action oppositeAction;
46 }