D:\NewZebra\JavaApplications\DesignPatternsProject\src\behavior_patterns\command_pattern_w_objects\CoreCommandsPerformer.java |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package behavior_patterns.command_pattern_w_objects;
21
22
23
24 @author
25
26
27
28 import java.text.*;
29 import java.util.*;
30 import java.awt.event.*;
31 import java.awt.*;
32 import javax.swing.*;
33
34
35 public class CoreCommandsPerformer extends JFrame implements CommandsPerformer{
36
37 final int X_STARTING_POSITION = 50;
38 final int Y_STARTING_POSITION = 50;
39
40 int local_X_position = X_STARTING_POSITION;
41 int local_Y_position = Y_STARTING_POSITION;
42
43 JButton aJButton = null;
44 CommandPanel aCommandPanel = null;
45
46
47
48 public CoreCommandsPerformer() {
49
50 setSize(800, 600);
51 setTitle(" Command Pattern W Objects JFrame");
52 setLayout(null);
53
54 instantiateCommandPanel();
55 queuingCommands();
56 runCommands();
57
58 setVisible(true);
59 }
60
61
62
63 public void instantiateCommandPanel(){
64 aCommandPanel = new CommandPanel();
65 aCommandPanel.setBounds(0,0,800,600);
66 aCommandPanel.setBackground(Color.lightGray);
67 aCommandPanel.setLayout(null);
68 add(aCommandPanel);
69 }
70
71
72
73 public void queuingCommands(){
74
75 if(aCommandPanel != null) {
76 addButton("Red", 0, new Command_1());
77 addButton("Gray", 40, new Command_2());
78 addButton("Blue", 80, new Command_3());
79 }
80 }
81
82
83
84 public void runCommands(){
85
86 }
87
88
89
90 public void addButton(String buttonName, int verticalPosition, Command passedCommand){
91
92 if(null == passedCommand)
93 return;
94
95 final Command localCommand = passedCommand;
96 local_Y_position += 40 + verticalPosition;
97
98 Cursor handCursor = new Cursor(Cursor.HAND_CURSOR);
99
100 aJButton = new JButton(buttonName);
101 aJButton.setCursor(handCursor);
102 aJButton.setBackground(Color.white);
103 aJButton.setBounds(local_X_position, local_Y_position, 100, 20);
104 aCommandPanel.add(aJButton);
105 aJButton.addActionListener(new ActionListener()
106 {
107 public void actionPerformed(ActionEvent PassedActionEvent)
108 {
109 localCommand.execute(aCommandPanel);
110 }
111 });
112 }
113
114
115
116
117 public static void main (String[] args) {
118 CoreCommandsPerformer coreCommandsPerformerHandle = new CoreCommandsPerformer();
119 }
120
121 }
122
123