-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui5.java
420 lines (370 loc) · 17 KB
/
gui5.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.*;
/**
* FitList
* 8 May 2022
* CIS111BONL02 - Dr. Martin
* @authors Julia Hansford, Chris Bonner, Geoffrey Gaines
*
* Categorize the queries that will be available for the user to choose from via JCbeckBox.
* Create the tools and features needed to design an efficient, user-friendly GUI.
* Create containers for objects to dwell in until they are called and to make GUI items.
* Create instance of youtubeAPI so method videoSearch() can be applied to user query choice via ActionListener.
*/
public class gui5
{
protected String[] optionsToChoose = {"Cardio", "Arms", "Legs", "Push", "Pull"};
protected String[] cardioOptions = {"Swimming", "Running", "Cycling", "Jump Rope", "Walking"};
protected String[] armsOptions = {"Bicep", "Forearm", "Tricep", "Chin-up", "Seated Row"};
protected String[] legsOptions = {"Squat", "Lunge", "Calf Raise", "Leg Press", "Deadlift"};
protected String[] pushOptions = {"Chest", "Shoulder", "Dips", "Push-up", "Pressing"};
protected String[] pullOptions = {"Shrug", "Lat Pulldown", "Pull-up", "Back", "Dumbbell Row"};
protected JComboBox<String> jComboBox = new JComboBox<>(optionsToChoose); //makes drop down list for homeFrame
protected JFrame homeFrame, cardioFrame, armsFrame, legsFrame, pushFrame, pullFrame;
protected JLabel homeLabel, cardioLabel, armsLabel, legsLabel, pushLabel, pullLabel; // label for subselection options
protected JButton btnOpenWindow, cardioSearch, armsSearch, legsSearch, pushSearch, pullSearch;
protected JLabel cardioResultLabel, armsResultLabel, legsResultLabel, pushResultLabel, pullResultLabel;
protected JTextArea cardioTxtArea, armsTxtArea, legsTxtArea, pushTxtArea, pullTxtArea;
protected youtubeAPI api = new youtubeAPI();
protected String urlCardio = "";
protected ArrayList<JCheckBox> cardioCheckBoxes = new ArrayList<JCheckBox>();
protected String urlArms = "";
protected ArrayList<JCheckBox> armsCheckBoxes = new ArrayList<JCheckBox>();
protected String urlLegs = "";
protected ArrayList<JCheckBox> legsCheckBoxes = new ArrayList<JCheckBox>();
protected String urlPush = "";
protected ArrayList<JCheckBox> pushCheckBoxes = new ArrayList<JCheckBox>();
protected String urlPull = "";
protected ArrayList<JCheckBox> pullCheckBoxes = new ArrayList<JCheckBox>();
/**
* Launch the application.
* GUI class can act as its own Driver class since it utilizes main method.
* Call the GUI constructor so homeFrame may appear and allow user to decide the sequence of events.
*/
public static void main(String[] args)
{
gui5 window = new gui5();
window.homeFrame.setVisible(true);
}
/**
* Create the application and objects that populate the GUI.
* Assign locations and properties of objects in second frame corresponding to user input selection.
* Automatically create JCheckBoxes for each category by looping through String[]'s declared above.
* Call method initialize().
*/
public gui5()
{
jComboBox.setBounds(275, 200, 140, 20);
homeLabel = new JLabel("Choose which type of exercise you are focusing on today");
homeLabel.setBounds(140,140,333,20);
int x = 100;
int y = 100;
int width = 150;
int height = 20;
for (int j = 0; j < cardioOptions.length; j++)
{
cardioCheckBoxes.add(new JCheckBox(cardioOptions[j]));
cardioCheckBoxes.get(j).setBounds(x, y, width, height);
y += 50;
}
y = 50;
cardioLabel = new JLabel("Choose your cardio exercise for today"); //label before checkboxes
cardioLabel.setBounds(x-50,y,width+ 150,height);
cardioSearch = new JButton("Search");
cardioSearch.setBounds(x +150,y +150,width -30,height);
cardioResultLabel = new JLabel("Results of the search");
cardioResultLabel.setBounds(x-50,350,width,height); //places above text area
cardioTxtArea = new JTextArea(30, 30);
cardioTxtArea.setBounds(x-50,y + 350,width + 350,height +130);
cardioTxtArea.setEditable(false); //user can't manipulate output
y = 100;
for (int l = 0; l < armsOptions.length; l++)
{
armsCheckBoxes.add(new JCheckBox(armsOptions[l]));
armsCheckBoxes.get(l).setBounds(x, y, width, height);
y += 50;
}
y = 50;
armsLabel = new JLabel("Choose your arm exercise for today"); //label before checkboxes
armsLabel.setBounds(x-50,y,width+ 150,height);
armsSearch = new JButton("Search");
armsSearch.setBounds(x +150,y +150,width -30,height);
armsResultLabel = new JLabel("Results of the search");
armsResultLabel.setBounds(x-50,350,width,height); //places above text area
armsTxtArea = new JTextArea(30, 30);
armsTxtArea.setBounds(x-50,y + 350,width + 350,height +130);
armsTxtArea.setEditable(false);
y = 100;
for (int o = 0; o < legsOptions.length; o++)
{
legsCheckBoxes.add(new JCheckBox(legsOptions[o]));
legsCheckBoxes.get(o).setBounds(x, y, width, height);
y += 50;
}
y = 50;
legsLabel = new JLabel("Choose your leg exercise for today"); //label before checkboxes
legsLabel.setBounds(x-50,y,width+ 150,height);
legsSearch = new JButton("Search");
legsSearch.setBounds(x +150,y +150,width -30,height);
legsResultLabel = new JLabel("Results of the search");
legsResultLabel.setBounds(x-50,350,width,height); //places above text area
legsTxtArea = new JTextArea(30, 30);
legsTxtArea.setBounds(x-50,y + 350,width + 350,height +130);
legsTxtArea.setEditable(false);
y = 100;
for (int r = 0; r < pushOptions.length; r++)
{
pushCheckBoxes.add(new JCheckBox(pushOptions[r]));
pushCheckBoxes.get(r).setBounds(x, y, width, height);
y += 50;
}
y = 50;
pushLabel = new JLabel("Choose your push exercise for today"); //label before checkboxes
pushLabel.setBounds(x-50,y,width+ 150,height);
pushSearch = new JButton("Search");
pushSearch.setBounds(x +150,y +150,width -30,height);
pushResultLabel = new JLabel("Results of the search");
pushResultLabel.setBounds(x-50,350,width,height); //places above text area
pushTxtArea = new JTextArea(30, 30);
pushTxtArea.setBounds(x-50,y + 350,width + 350,height +130);
pushTxtArea.setEditable(false);
y = 100;
for (int u = 0; u < pullOptions.length; u++)
{
pullCheckBoxes.add(new JCheckBox(pullOptions[u]));
pullCheckBoxes.get(u).setBounds(x, y, width, height);
y += 50;
}
y = 50;
pullLabel = new JLabel("Choose your pull exercise for today"); //label before checkboxes
pullLabel.setBounds(x-50,y,width+ 150,height);
pullSearch = new JButton("Search");
pullSearch.setBounds(x +150,y +150,width -30,height);
pullResultLabel = new JLabel("Results of the search");
pullResultLabel.setBounds(x-50,350,width,height); //places above text area
pullTxtArea = new JTextArea(30, 30);
pullTxtArea.setBounds(x-50,y + 350,width + 350,height +130);
pullTxtArea.setEditable(false);
y = 100;
initialize();
}
/**
* Initialize the contents of the frames and assign object properties/positions.
* Edit and critique each second frame possibility so they look professional with similar object placement.
* Register ActionListener with multiple JButtons so proper functionality may occur.
* Call api object in each Search Button so JCheckBox selection can be passed as String in method videoSearch().
* @exception ClassCastException
*/
protected void initialize()
{
homeFrame = new JFrame(); //makes first frame
homeFrame.setBounds(100, 100, 650, 400); // makes size of frame and where it opens
homeFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
homeFrame.getContentPane().setLayout(null);
homeFrame.add(jComboBox);
homeFrame.add(homeLabel);
JButton btnOpenWindow = new JButton("Next");
btnOpenWindow.setBounds(300, 300, 100, 33);
homeFrame.getContentPane().add(btnOpenWindow);
cardioFrame = new JFrame(); //makes cardio frame
cardioFrame.setBounds(100, 100, 650, 600); //sets size and postion
cardioFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //tells what to do when frame is closed
cardioFrame.getContentPane().setLayout(null);
//adding check boxes to frame
for (int k = 0; k < cardioOptions.length; k++)
{
cardioFrame.add(cardioCheckBoxes.get(k));
}
//adding labels button and text area to the frame
cardioFrame.add(cardioSearch);//adding search button to frame
cardioFrame.add(cardioLabel);
cardioFrame.add(cardioResultLabel);
cardioFrame.add(cardioTxtArea);
armsFrame = new JFrame(); //makes arms frame
armsFrame.setBounds(100, 100, 650, 600); //sets size and postion
armsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //tells what to do when frame is closed
armsFrame.getContentPane().setLayout(null);
for (int m = 0; m < armsOptions.length; m++)
{
armsFrame.add(armsCheckBoxes.get(m));
}
armsFrame.add(armsSearch);//adding search button to frame
armsFrame.add(armsLabel);
armsFrame.add(armsResultLabel);
armsFrame.add(armsTxtArea);
legsFrame = new JFrame(); //makes cardio frame
legsFrame.setBounds(100, 100, 650, 600); //sets size and postion
legsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //tells what to do when frame is closed
legsFrame.getContentPane().setLayout(null);
for (int p = 0; p < legsOptions.length; p++)//adding check boxes to frame
{
legsFrame.add(legsCheckBoxes.get(p));
}
//adding labels button and text area to the frame
legsFrame.add(legsSearch);//adding search button to frame
legsFrame.add(legsLabel);
legsFrame.add(legsResultLabel);
legsFrame.add(legsTxtArea);
pushFrame = new JFrame(); //makes cardio frame
pushFrame.setBounds(100, 100, 650, 600); //sets size and position
pushFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //tells what to do when frame is closed
pushFrame.getContentPane().setLayout(null);
for (int s = 0; s < legsOptions.length; s++)//adding check boxes to frame
{
pushFrame.add(pushCheckBoxes.get(s));
}
//adding labels button and text area to the frame
pushFrame.add(pushSearch);//adding search button to frame
pushFrame.add(pushLabel);
pushFrame.add(pushResultLabel);
pushFrame.add(pushTxtArea);
pullFrame = new JFrame(); //makes cardio frame
pullFrame.setBounds(100, 100, 650, 600); //sets size and postion
pullFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //tells what to do when frame is closed
pullFrame.getContentPane().setLayout(null);
for (int v = 0; v < pullOptions.length; v++)//adding check boxes to frame
{
pullFrame.add(pullCheckBoxes.get(v));
}
//adding labels button and text area to the frame
pullFrame.add(pullSearch);//adding search button to frame
pullFrame.add(pullLabel);
pullFrame.add(pullResultLabel);
pullFrame.add(pullTxtArea);
//registering next button with actionListener
btnOpenWindow.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
if (jComboBox.getSelectedItem().equals("Cardio"))
cardioFrame.setVisible(true);
else if (jComboBox.getSelectedItem().equals("Arms"))
armsFrame.setVisible(true);
else if (jComboBox.getSelectedItem().equals("Legs"))
legsFrame.setVisible(true);
else if (jComboBox.getSelectedItem().equals("Push"))
pushFrame.setVisible(true);
else if (jComboBox.getSelectedItem().equals("Pull"))
pullFrame.setVisible(true);
}
});
//registering cardioSearch
cardioSearch.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
cardioTxtArea.setText("");
for (int i = 0; i< cardioCheckBoxes.size(); i++)
{
if(cardioCheckBoxes.get(i).isSelected())
{
urlCardio = (api.videoSearch(cardioCheckBoxes.get(i).getText() + "exercises"));
cardioTxtArea.append(cardioOptions[i] + " video: \n");
cardioTxtArea.append(urlCardio + "\n");
}
}
}
catch(ClassCastException ex) //catch(IOException | Exception ex)
{
System.out.println(ex);
}
}
});//end cardioSearch Action Listener
armsSearch.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
armsTxtArea.setText("");
for (int n = 0; n< armsCheckBoxes.size(); n++)
{
if(armsCheckBoxes.get(n).isSelected())
{
urlArms = (api.videoSearch(armsCheckBoxes.get(n).getText() + "exercises"));
armsTxtArea.append(armsOptions[n] + " video: \n");
armsTxtArea.append(urlArms + "\n");
}
}
}
catch(ClassCastException ex) //catch(IOException | Exception ex)
{
System.out.println(ex);
}
}
});//end armsSearch Action Listener
legsSearch.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
legsTxtArea.setText("");
for (int q = 0; q< legsCheckBoxes.size(); q++)
{
if(legsCheckBoxes.get(q).isSelected())
{
urlLegs = (api.videoSearch(legsCheckBoxes.get(q).getText() + "exercises"));
legsTxtArea.append(legsOptions[q] + " video: \n");
legsTxtArea.append(urlLegs + "\n");
}
}
}
catch(ClassCastException ex) //catch(IOException | Exception ex)
{
System.out.println(ex);
}
}
});//end legsSearch Action Listener
pushSearch.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
pushTxtArea.setText("");
for (int t = 0; t< pushCheckBoxes.size(); t++)
{
if(pushCheckBoxes.get(t).isSelected())
{
urlPush = (api.videoSearch(pushCheckBoxes.get(t).getText() + "exercises"));
pushTxtArea.append(pushOptions[t] + " video: \n");
pushTxtArea.append(urlPush + "\n");
}
}
}
catch(ClassCastException ex) //catch(IOException | Exception ex)
{
System.out.println(ex);
}
}
});//end pushSearch Action Listener
pullSearch.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
pullTxtArea.setText("");
for (int w = 0; w < pullCheckBoxes.size(); w++)
{
if(pullCheckBoxes.get(w).isSelected())
{
urlPull = (api.videoSearch(pullCheckBoxes.get(w).getText() + "exercises"));
pullTxtArea.append(pullOptions[w] + " video: \n");
pullTxtArea.append(urlPull + "\n");
}
}
}
catch(ClassCastException ex) //catch(IOException | Exception ex)
{
System.out.println(ex);
}
}
});//end pullSearch Action Listener
}//end method initialize()
}//end class