/home/sjenks/NetBeansProjects/CS2/src/frames/SV1Frame.java |
1
2
3
4 package frames;
5
6 import java.awt.BorderLayout;
7 import java.awt.Color;
8 import java.awt.Container;
9 import java.awt.Dimension;
10 import java.awt.FlowLayout;
11 import java.awt.GridLayout;
12 import java.awt.event.ActionEvent;
13 import java.awt.event.ActionListener;
14 import javax.swing.JButton;
15 import javax.swing.JFrame;
16 import javax.swing.JPanel;
17 import javax.swing.JTextArea;
18 import javax.swing.JTextField;
19
20
21
22
23 @author
24
25 public class SV1Frame extends JFrame implements ActionListener {
26
27
28 JButton blueButton;
29 JButton redButton;
30 JButton yellowButton;
31 JButton colorButton;
32 JButton mfdButton;
33 JButton mbkButton;
34 JButton mrtButton;
35 JButton mltButton;
36 JButton lrtButton;
37 JButton lltButton;
38 JButton lmfButton;
39 JButton srtButton;
40 JButton sltButton;
41 JButton nopButton;
42 JButton clearButton;
43 JButton cleanButton;
44 JButton resetButton;
45 JButton thing1Button;
46 JButton thing2Button;
47 JButton thing3Button;
48 JButton thing4Button;
49 JButton thing5Button;
50 JPanel reflector;
51 JTextArea output;
52 JTextField input;
53
54 public SV1Frame(String title) {
55 super(title);
56 setSize(900,700);
57 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
58 addComponents(getContentPane());
59 addListeners();
60 setVisible(true);
61 setResizable(false);
62 }
63
64 private void addComponents(Container contentPane) {
65
66 clearButton = new JButton("Clear");
67 cleanButton = new JButton("Clean");
68 resetButton = new JButton("Reset");
69 JPanel controlPanel = new JPanel();
70 controlPanel.setLayout(new FlowLayout());
71 controlPanel.add(resetButton);
72 controlPanel.add(cleanButton);
73 controlPanel.add(clearButton);
74
75
76 blueButton = new JButton("BLUE");
77 redButton = new JButton("RED");
78 yellowButton = new JButton("YELLOW");
79 colorButton = new JButton("COLOR");
80 mfdButton = new JButton("MFD");
81 mbkButton = new JButton("MBK");
82 mrtButton = new JButton("MRT");
83 mltButton = new JButton("MLT");
84 lrtButton = new JButton("LRT");
85 lltButton = new JButton("LLT");
86 lmfButton = new JButton("LMF");
87 srtButton = new JButton("SRT");
88 sltButton = new JButton("SLT");
89 nopButton = new JButton("NOP");
90 JPanel wControlPanel = new JPanel();
91 wControlPanel.setLayout(new GridLayout(14,1));
92 wControlPanel.add(blueButton);
93 wControlPanel.add(redButton);
94 wControlPanel.add(yellowButton);
95 wControlPanel.add(colorButton);
96 wControlPanel.add(mfdButton);
97 wControlPanel.add(mbkButton);
98 wControlPanel.add(mrtButton);
99 wControlPanel.add(mltButton);
100 wControlPanel.add(lrtButton);
101 wControlPanel.add(lltButton);
102 wControlPanel.add(lmfButton);
103 wControlPanel.add(srtButton);
104 wControlPanel.add(sltButton);
105 wControlPanel.add(nopButton);
106
107
108 thing1Button = new JButton("THING 1");
109 thing2Button = new JButton("THING 2");
110 thing3Button = new JButton("THING 3");
111 thing4Button = new JButton("THING 4");
112 thing5Button = new JButton("THING 5");
113 JPanel eControlPanel = new JPanel();
114 eControlPanel.setLayout(new GridLayout(5,1));
115 eControlPanel.add(thing1Button);
116 eControlPanel.add(thing2Button);
117 eControlPanel.add(thing3Button);
118 eControlPanel.add(thing4Button);
119 eControlPanel.add(thing5Button);
120
121
122 int width = 730; int height = 315;
123 reflector = new JPanel();
124 reflector.setSize(new Dimension(width,height));
125 reflector.setBackground(Color.WHITE);
126 output = new JTextArea(width,height);
127 output.setBackground(Color.WHITE);
128 output.setWrapStyleWord(true);
129 output.setLineWrap(true);
130 Container centralRegion = new Container();
131 centralRegion.setLayout(new GridLayout(2,1,6,6));
132 centralRegion.add(reflector);
133 centralRegion.add(output);
134
135
136 input = new JTextField();
137
138 contentPane.setLayout(new BorderLayout());
139 contentPane.add(controlPanel, BorderLayout.NORTH);
140 contentPane.add(eControlPanel, BorderLayout.EAST);
141 contentPane.add(wControlPanel, BorderLayout.WEST);
142 contentPane.add(centralRegion, BorderLayout.CENTER);
143 contentPane.add(input, BorderLayout.SOUTH);
144
145 }
146
147
148 private void addListeners() {
149 redButton.addActionListener(this);
150 blueButton.addActionListener(this);
151 yellowButton.addActionListener(this);
152 colorButton.addActionListener(this);
153 mfdButton.addActionListener(this);
154 mbkButton.addActionListener(this);
155 mrtButton.addActionListener(this);
156 mltButton.addActionListener(this);
157 lmfButton.addActionListener(this);
158 srtButton.addActionListener(this);
159 sltButton.addActionListener(this);
160 lrtButton.addActionListener(this);
161 lltButton.addActionListener(this);
162 nopButton.addActionListener(this);
163 cleanButton.addActionListener(this);
164 clearButton.addActionListener(this);
165 resetButton.addActionListener(this);
166 thing1Button.addActionListener(this);
167 thing2Button.addActionListener(this);
168 thing3Button.addActionListener(this);
169 thing4Button.addActionListener(this);
170 thing5Button.addActionListener(this);
171 input.addActionListener(this);
172 }
173
174
175 public void actionPerformed(ActionEvent event) {
176 String command = event.getActionCommand();
177 processCommand(command);
178 if (event.getSource() instanceof JTextField){
179 input.setText("");
180 }
181 }
182 private void processCommand(String command){
183
184 if (command.equalsIgnoreCase("RED")) {
185 output.append("RED ");
186 } else if (command.equalsIgnoreCase("YELLOW")) {
187 output.append("YELLOW ");
188 } else if (command.equalsIgnoreCase("BLUE")) {
189 output.append("Blue ");
190 } else if (command.equalsIgnoreCase("COLOR")) {
191 output.append("COLOR ");
192 } else if (command.equalsIgnoreCase("MFD")) {
193 output.append("MFD ");
194 } else if (command.equalsIgnoreCase("MBK")) {
195 output.append("MBK ");
196 } else if (command.equalsIgnoreCase("MRT")) {
197 output.append("MRT ");
198 } else if (command.equalsIgnoreCase("MLT")) {
199 output.append("MLT ");
200 } else if (command.equalsIgnoreCase("LRT")) {
201 output.append("LRT ");
202 } else if (command.equalsIgnoreCase("LLT")) {
203 output.append("LLT ");
204 } else if (command.equalsIgnoreCase("LMF")) {
205 output.append("LMF ");
206 } else if (command.equalsIgnoreCase("SRT")) {
207 output.append("SRT ");
208 } else if (command.equalsIgnoreCase("SLT")) {
209 output.append("SLT ");
210 } else if (command.equalsIgnoreCase("NOP")) {
211 output.append("NOP ");
212 }else if (command.equalsIgnoreCase("CLEAN")) {
213 output.append("CLEAN ");
214 } else if (command.equalsIgnoreCase("CLEAR")) {
215 output.append("CLEAR ");
216 } else if (command.equalsIgnoreCase("RESET")) {
217 output.append("RESET ");
218 } else if (command.equalsIgnoreCase("THING 1")) {
219 output.append("THING 1 ");
220 }else if (command.equalsIgnoreCase("THING 2")) {
221 output.append("THING 2 ");
222 } else if (command.equalsIgnoreCase("THING 3")) {
223 output.append("THING 3 ");
224 } else if (command.equalsIgnoreCase("THING 4")) {
225 output.append("THING 4 ");
226 } else if (command.equalsIgnoreCase("THING 5")) {
227 output.append("THING 5 ");
228 }else{
229 output.append("### UNRECOGNIZED COMMAND: " + command.toUpperCase()+ "###");
230 }
231 }
232 }
233
234
235
236
237
238
239