/Users/18812/Desktop/Computer Science IA/Chun - IA/src/recipeOrganizer/MainGUIForRecipes.java |
1
2
3
4
5
6 package recipeOrganizer;
7
8 import javax.swing.JOptionPane;
9 import javax.swing.table.DefaultTableModel;
10
11
12
13 @author
14
15 public class MainGUIForRecipes extends javax.swing.JFrame {
16
17
18
19
20 private RecipeClass [] recipes;
21 int counter = 0;
22
23 SortAndSearchRecipes sortClass = new SortAndSearchRecipes();
24
25
26
27 public MainGUIForRecipes() {
28 initComponents();
29 myInit();
30 }
31
32
33 private void myInit(){
34 recipes = new RecipeClass[99];
35 for(int i = 0; i < recipes.length; i++){
36 recipes[i] = new RecipeClass();
37 }
38 }
39
40 private void refresh(){
41 for(int i = 0; i < recipes.length; i++){
42 if(recipes[i].getTimeRequired() != 999999999){
43 recipeListTable.setValueAt(recipes[i].getRecipeName(), i, 0);
44 recipeListTable.setValueAt(recipes[i].getCategory()[0] + " " +
45 recipes[i].getCategory()[1] + " " +
46 recipes[i].getCategory()[2]+ " " +
47 recipes[i].getCategory()[3]+ " "+
48 recipes[i].getCategory()[4]+ " "+
49 recipes[i].getCategory()[5] + " " +
50 recipes[i].getCategory()[6] + " " +
51 recipes[i].getCategory()[7]+ " "+
52 recipes[i].getCategory()[8]+ " "+
53 recipes[i].getCategory()[9], i, 1);
54 recipeListTable.setValueAt(recipes[i].getIngredient(), i, 2);
55 recipeListTable.setValueAt(recipes[i].getInstruction(), i, 3);
56 recipeListTable.setValueAt(recipes[i].getRecordedDate(), i, 4);
57 recipeListTable.setValueAt(recipes[i].getTimeRequired(), i, 5);
58 }
59 }
60 }
61
62
63 This method is called from within the constructor to initialize the form.
64
65
66
67 @SuppressWarnings("unchecked")
68 // <editor-fold defaultstate="collapsed" desc="Generated Code">
69 private void initComponents() {
70
71 jFrame1 = new javax.swing.JFrame();
72 tabs = new javax.swing.JTabbedPane();
73 listRecipe = new javax.swing.JPanel();
74 tableScroll = new javax.swing.JScrollPane();
75 recipeListTable = new javax.swing.JTable();
76 sortByAlphabetBt = new javax.swing.JButton();
77 sortByNewestBt = new javax.swing.JButton();
78 jLabel11 = new javax.swing.JLabel();
79 refreshListBt = new javax.swing.JButton();
80 jLabel12 = new javax.swing.JLabel();
81 deleteBt1 = new javax.swing.JButton();
82 searchRecipe = new javax.swing.JPanel();
83 nameTf = new javax.swing.JTextField();
84 jLabel7 = new javax.swing.JLabel();
85 jScrollPane1 = new javax.swing.JScrollPane();
86 searchListTable = new javax.swing.JTable();
87 searchBt = new javax.swing.JButton();
88 jLabel9 = new javax.swing.JLabel();
89 findComboBox = new javax.swing.JComboBox<>();
90 addRecipe = new javax.swing.JPanel();
91 saveBt = new javax.swing.JButton();
92 jLabel1 = new javax.swing.JLabel();
93 nameTf2 = new javax.swing.JTextField();
94 jLabel2 = new javax.swing.JLabel();
95 ingredientTf2 = new javax.swing.JTextField();
96 jLabel3 = new javax.swing.JLabel();
97 monthComboBox2 = new javax.swing.JComboBox<>();
98 instructionsTf2 = new javax.swing.JTextField();
99 jLabel4 = new javax.swing.JLabel();
100 dayComboBox2 = new javax.swing.JComboBox<>();
101 yearComboBox2 = new javax.swing.JComboBox<>();
102 jLabel10 = new javax.swing.JLabel();
103 appetizerRB2 = new javax.swing.JRadioButton();
104 soupsRB2 = new javax.swing.JRadioButton();
105 pastaRB2 = new javax.swing.JRadioButton();
106 sideDishRB2 = new javax.swing.JRadioButton();
107 mainDishRB2 = new javax.swing.JRadioButton();
108 meatRB2 = new javax.swing.JRadioButton();
109 seafoodRB2 = new javax.swing.JRadioButton();
110 dessertRB2 = new javax.swing.JRadioButton();
111 drinksRB2 = new javax.swing.JRadioButton();
112 specialRecipeRB2 = new javax.swing.JRadioButton();
113 resetBt = new javax.swing.JButton();
114 jLabel8 = new javax.swing.JLabel();
115 timeRequiredTf2 = new javax.swing.JTextField();
116 menuBar = new javax.swing.JMenuBar();
117 fileMenu = new javax.swing.JMenu();
118 openMenuItem = new javax.swing.JMenuItem();
119 saveMenuItem = new javax.swing.JMenuItem();
120 saveAsMenuItem = new javax.swing.JMenuItem();
121 exitMenuItem = new javax.swing.JMenuItem();
122 editMenu = new javax.swing.JMenu();
123 cutMenuItem = new javax.swing.JMenuItem();
124 copyMenuItem = new javax.swing.JMenuItem();
125 pasteMenuItem = new javax.swing.JMenuItem();
126 deleteMenuItem = new javax.swing.JMenuItem();
127 helpMenu = new javax.swing.JMenu();
128 contentsMenuItem = new javax.swing.JMenuItem();
129 aboutMenuItem = new javax.swing.JMenuItem();
130
131 javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
132 jFrame1.getContentPane().setLayout(jFrame1Layout);
133 jFrame1Layout.setHorizontalGroup(
134 jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
135 .addGap(0, 400, Short.MAX_VALUE)
136 );
137 jFrame1Layout.setVerticalGroup(
138 jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
139 .addGap(0, 300, Short.MAX_VALUE)
140 );
141
142 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
143
144 recipeListTable.setModel(new javax.swing.table.DefaultTableModel(
145 new Object [][] {
146 {null, null, null, null, null, null},
147 {null, null, null, null, null, null},
148 {null, null, null, null, null, null},
149 {null, null, null, null, null, null},
150 {null, null, null, null, null, null},
151 {null, null, null, null, null, null},
152 {null, null, null, null, null, null},
153 {null, null, null, null, null, null},
154 {null, null, null, null, null, null},
155 {null, null, null, null, null, null},
156 {null, null, null, null, null, null},
157 {null, null, null, null, null, null},
158 {null, null, null, null, null, null},
159 {null, null, null, null, null, null},
160 {null, null, null, null, null, null},
161 {null, null, null, null, null, null},
162 {null, null, null, null, null, null},
163 {null, null, null, null, null, null},
164 {null, null, null, null, null, null},
165 {null, null, null, null, null, null},
166 {null, null, null, null, null, null},
167 {null, null, null, null, null, null},
168 {null, null, null, null, null, null},
169 {null, null, null, null, null, null},
170 {null, null, null, null, null, null},
171 {null, null, null, null, null, null},
172 {null, null, null, null, null, null},
173 {null, null, null, null, null, null},
174 {null, null, null, null, null, null},
175 {null, null, null, null, null, null},
176 {null, null, null, null, null, null},
177 {null, null, null, null, null, null},
178 {null, null, null, null, null, null},
179 {null, null, null, null, null, null},
180 {null, null, null, null, null, null},
181 {null, null, null, null, null, null},
182 {null, null, null, null, null, null},
183 {null, null, null, null, null, null},
184 {null, null, null, null, null, null},
185 {null, null, null, null, null, null},
186 {null, null, null, null, null, null},
187 {null, null, null, null, null, null},
188 {null, null, null, null, null, null},
189 {null, null, null, null, null, null},
190 {null, null, null, null, null, null},
191 {null, null, null, null, null, null},
192 {null, null, null, null, null, null},
193 {null, null, null, null, null, null},
194 {null, null, null, null, null, null},
195 {null, null, null, null, null, null},
196 {null, null, null, null, null, null},
197 {null, null, null, null, null, null},
198 {null, null, null, null, null, null},
199 {null, null, null, null, null, null},
200 {null, null, null, null, null, null},
201 {null, null, null, null, null, null},
202 {null, null, null, null, null, null},
203 {null, null, null, null, null, null},
204 {null, null, null, null, null, null},
205 {null, null, null, null, null, null},
206 {null, null, null, null, null, null},
207 {null, null, null, null, null, null},
208 {null, null, null, null, null, null},
209 {null, null, null, null, null, null},
210 {null, null, null, null, null, null},
211 {null, null, null, null, null, null},
212 {null, null, null, null, null, null},
213 {null, null, null, null, null, null},
214 {null, null, null, null, null, null},
215 {null, null, null, null, null, null},
216 {null, null, null, null, null, null},
217 {null, null, null, null, null, null},
218 {null, null, null, null, null, null},
219 {null, null, null, null, null, null},
220 {null, null, null, null, null, null},
221 {null, null, null, null, null, null},
222 {null, null, null, null, null, null},
223 {null, null, null, null, null, null},
224 {null, null, null, null, null, null},
225 {null, null, null, null, null, null},
226 {null, null, null, null, null, null},
227 {null, null, null, null, null, null},
228 {null, null, null, null, null, null},
229 {null, null, null, null, null, null},
230 {null, null, null, null, null, null},
231 {null, null, null, null, null, null},
232 {null, null, null, null, null, null},
233 {null, null, null, null, null, null},
234 {null, null, null, null, null, null},
235 {null, null, null, null, null, null},
236 {null, null, null, null, null, null},
237 {null, null, null, null, null, null},
238 {null, null, null, null, null, null},
239 {null, null, null, null, null, null},
240 {null, null, null, null, null, null},
241 {null, null, null, null, null, null},
242 {null, null, null, null, null, null},
243 {null, null, null, null, null, null},
244 {null, null, null, null, null, null}
245 },
246 new String [] {
247 "Name", "Category", "Ingredient", "Instructions", "Date Added", "Time"
248 }
249 ) {
250 Class[] types = new Class [] {
251 java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class
252 };
253
254 public Class getColumnClass(int columnIndex) {
255 return types [columnIndex];
256 }
257 });
258 recipeListTable.setGridColor(new java.awt.Color(0, 0, 0));
259 tableScroll.setViewportView(recipeListTable);
260 if (recipeListTable.getColumnModel().getColumnCount() > 0) {
261 recipeListTable.getColumnModel().getColumn(0).setMaxWidth(80);
262 recipeListTable.getColumnModel().getColumn(1).setMaxWidth(150);
263 recipeListTable.getColumnModel().getColumn(5).setMaxWidth(50);
264 }
265
266 sortByAlphabetBt.setText("Alphabet");
267 sortByAlphabetBt.addMouseListener(new java.awt.event.MouseAdapter() {
268 public void mouseReleased(java.awt.event.MouseEvent evt) {
269 sortByAlphabetBtMouseReleased(evt);
270 }
271 });
272
273 sortByNewestBt.setText("Date");
274 sortByNewestBt.addMouseListener(new java.awt.event.MouseAdapter() {
275 public void mouseReleased(java.awt.event.MouseEvent evt) {
276 sortByNewestBtMouseReleased(evt);
277 }
278 });
279
280 jLabel11.setText("Sort by:");
281
282 refreshListBt.setText("Refresh");
283 refreshListBt.addMouseListener(new java.awt.event.MouseAdapter() {
284 public void mouseReleased(java.awt.event.MouseEvent evt) {
285 refreshListBtMouseReleased(evt);
286 }
287 });
288
289 jLabel12.setText("Options:");
290
291 deleteBt1.setText("Delete ");
292 deleteBt1.addActionListener(new java.awt.event.ActionListener() {
293 public void actionPerformed(java.awt.event.ActionEvent evt) {
294 deleteBt1ActionPerformed(evt);
295 }
296 });
297
298 javax.swing.GroupLayout listRecipeLayout = new javax.swing.GroupLayout(listRecipe);
299 listRecipe.setLayout(listRecipeLayout);
300 listRecipeLayout.setHorizontalGroup(
301 listRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
302 .addGroup(listRecipeLayout.createSequentialGroup()
303 .addGroup(listRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
304 .addComponent(tableScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 762, Short.MAX_VALUE)
305 .addGroup(listRecipeLayout.createSequentialGroup()
306 .addContainerGap()
307 .addGroup(listRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
308 .addComponent(jLabel11)
309 .addComponent(jLabel12))
310 .addGap(7, 7, 7)
311 .addGroup(listRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
312 .addComponent(refreshListBt, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
313 .addComponent(sortByAlphabetBt, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
314 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
315 .addGroup(listRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
316 .addComponent(sortByNewestBt, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
317 .addComponent(deleteBt1))
318 .addGap(0, 0, Short.MAX_VALUE)))
319 .addContainerGap())
320 );
321 listRecipeLayout.setVerticalGroup(
322 listRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
323 .addGroup(listRecipeLayout.createSequentialGroup()
324 .addComponent(tableScroll, javax.swing.GroupLayout.PREFERRED_SIZE, 508, javax.swing.GroupLayout.PREFERRED_SIZE)
325 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
326 .addGroup(listRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
327 .addComponent(refreshListBt)
328 .addComponent(jLabel12)
329 .addComponent(deleteBt1))
330 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
331 .addGroup(listRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
332 .addComponent(jLabel11)
333 .addComponent(sortByAlphabetBt)
334 .addComponent(sortByNewestBt))
335 .addContainerGap(9, Short.MAX_VALUE))
336 );
337
338 tabs.addTab("Main Table", listRecipe);
339
340 nameTf.addActionListener(new java.awt.event.ActionListener() {
341 public void actionPerformed(java.awt.event.ActionEvent evt) {
342 nameTfActionPerformed(evt);
343 }
344 });
345
346 searchListTable.setModel(new javax.swing.table.DefaultTableModel(
347 new Object [][] {
348 {null, null, null, null, null, null},
349 {null, null, null, null, null, null},
350 {null, null, null, null, null, null},
351 {null, null, null, null, null, null}
352 },
353 new String [] {
354 "Name", "Category", "Ingredient", "Instructions", "Date Added", "Time "
355 }
356 ) {
357 Class[] types = new Class [] {
358 java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class
359 };
360
361 public Class getColumnClass(int columnIndex) {
362 return types [columnIndex];
363 }
364 });
365 searchListTable.setShowGrid(true);
366 jScrollPane1.setViewportView(searchListTable);
367 if (searchListTable.getColumnModel().getColumnCount() > 0) {
368 searchListTable.getColumnModel().getColumn(0).setMaxWidth(80);
369 searchListTable.getColumnModel().getColumn(1).setMaxWidth(150);
370 searchListTable.getColumnModel().getColumn(5).setMaxWidth(50);
371 }
372
373 searchBt.setText("Search");
374 searchBt.addMouseListener(new java.awt.event.MouseAdapter() {
375 public void mouseReleased(java.awt.event.MouseEvent evt) {
376 searchBtMouseReleased(evt);
377 }
378 });
379
380 jLabel9.setText("Find by:");
381
382 findComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Recipe Name", "Date Added" }));
383
384 javax.swing.GroupLayout searchRecipeLayout = new javax.swing.GroupLayout(searchRecipe);
385 searchRecipe.setLayout(searchRecipeLayout);
386 searchRecipeLayout.setHorizontalGroup(
387 searchRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
388 .addGroup(searchRecipeLayout.createSequentialGroup()
389 .addContainerGap()
390 .addGroup(searchRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
391 .addGroup(searchRecipeLayout.createSequentialGroup()
392 .addComponent(jLabel9)
393 .addGap(49, 49, 49)
394 .addComponent(findComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
395 .addGap(36, 36, 36)
396 .addComponent(nameTf, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)
397 .addGap(18, 18, 18)
398 .addComponent(searchBt))
399 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 748, javax.swing.GroupLayout.PREFERRED_SIZE))
400 .addGap(1219, 1219, 1219)
401 .addComponent(jLabel7)
402 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
403 );
404 searchRecipeLayout.setVerticalGroup(
405 searchRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
406 .addGroup(searchRecipeLayout.createSequentialGroup()
407 .addContainerGap()
408 .addGroup(searchRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
409 .addComponent(jLabel9)
410 .addComponent(findComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
411 .addComponent(searchBt)
412 .addComponent(nameTf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
413 .addGroup(searchRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
414 .addGroup(searchRecipeLayout.createSequentialGroup()
415 .addGap(141, 141, 141)
416 .addComponent(jLabel7))
417 .addGroup(searchRecipeLayout.createSequentialGroup()
418 .addGap(18, 18, 18)
419 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 505, javax.swing.GroupLayout.PREFERRED_SIZE)))
420 .addContainerGap(29, Short.MAX_VALUE))
421 );
422
423 tabs.addTab("Search Recipes", searchRecipe);
424
425 saveBt.setText("Save");
426 saveBt.addMouseListener(new java.awt.event.MouseAdapter() {
427 public void mouseReleased(java.awt.event.MouseEvent evt) {
428 saveBtMouseReleased(evt);
429 }
430 });
431
432 jLabel1.setText("Recipe Name:");
433
434 jLabel2.setText("Ingredient:");
435
436 jLabel3.setText("Instructions");
437
438 monthComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Dec" }));
439
440 instructionsTf2.addActionListener(new java.awt.event.ActionListener() {
441 public void actionPerformed(java.awt.event.ActionEvent evt) {
442 instructionsTf2ActionPerformed(evt);
443 }
444 });
445
446 jLabel4.setText("Enter Date (MM/DD/YY):");
447
448 dayComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "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", " " }));
449
450 yearComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "2018", "2019", "2020", "2021", "2022", "2023", "2024", "2025", "2026", "2027", "2028", "2029", "2030" }));
451
452 jLabel10.setText("Type of Dish");
453
454 appetizerRB2.setText("Appetizer");
455
456 soupsRB2.setText("Soups/Salads");
457
458 pastaRB2.setText("Pasta");
459
460 sideDishRB2.setText("Side Dish");
461
462 mainDishRB2.setText("Main Dish");
463
464 meatRB2.setText("Meat/Chicken");
465
466 seafoodRB2.setText("Seafood");
467
468 dessertRB2.setText("Dessert/Bread");
469
470 drinksRB2.setText("Drinks");
471
472 specialRecipeRB2.setText("Special Recipe");
473
474 resetBt.setText("Reset");
475 resetBt.addActionListener(new java.awt.event.ActionListener() {
476 public void actionPerformed(java.awt.event.ActionEvent evt) {
477 resetBtActionPerformed(evt);
478 }
479 });
480
481 jLabel8.setText("Time Required (min)");
482
483 javax.swing.GroupLayout addRecipeLayout = new javax.swing.GroupLayout(addRecipe);
484 addRecipe.setLayout(addRecipeLayout);
485 addRecipeLayout.setHorizontalGroup(
486 addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
487 .addGroup(addRecipeLayout.createSequentialGroup()
488 .addGroup(addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
489 .addGroup(addRecipeLayout.createSequentialGroup()
490 .addContainerGap()
491 .addGroup(addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
492 .addGroup(addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
493 .addGroup(addRecipeLayout.createSequentialGroup()
494 .addComponent(jLabel4)
495 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
496 .addComponent(monthComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
497 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
498 .addComponent(dayComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
499 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
500 .addComponent(yearComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
501 .addGap(330, 330, 330))
502 .addGroup(javax.swing.GroupLayout.Alignment.LEADING, addRecipeLayout.createSequentialGroup()
503 .addGroup(addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
504 .addComponent(jLabel3)
505 .addComponent(instructionsTf2, javax.swing.GroupLayout.PREFERRED_SIZE, 462, javax.swing.GroupLayout.PREFERRED_SIZE))
506 .addGap(18, 18, 18)
507 .addGroup(addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
508 .addComponent(jLabel10)
509 .addGroup(addRecipeLayout.createSequentialGroup()
510 .addGroup(addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
511 .addComponent(appetizerRB2)
512 .addComponent(soupsRB2)
513 .addComponent(pastaRB2)
514 .addComponent(sideDishRB2)
515 .addComponent(mainDishRB2))
516 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
517 .addGroup(addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
518 .addComponent(meatRB2)
519 .addComponent(seafoodRB2)
520 .addComponent(dessertRB2)
521 .addComponent(drinksRB2)
522 .addComponent(specialRecipeRB2)))
523 .addComponent(jLabel8)
524 .addComponent(timeRequiredTf2))))
525 .addComponent(jLabel2)
526 .addGroup(addRecipeLayout.createSequentialGroup()
527 .addComponent(jLabel1)
528 .addGap(28, 28, 28)
529 .addGroup(addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
530 .addComponent(ingredientTf2, javax.swing.GroupLayout.DEFAULT_SIZE, 610, Short.MAX_VALUE)
531 .addComponent(nameTf2)))))
532 .addGroup(addRecipeLayout.createSequentialGroup()
533 .addGap(288, 288, 288)
534 .addComponent(saveBt)
535 .addGap(39, 39, 39)
536 .addComponent(resetBt)))
537 .addContainerGap(38, Short.MAX_VALUE))
538 );
539 addRecipeLayout.setVerticalGroup(
540 addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
541 .addGroup(addRecipeLayout.createSequentialGroup()
542 .addGap(14, 14, 14)
543 .addGroup(addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
544 .addComponent(jLabel1)
545 .addComponent(nameTf2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
546 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
547 .addGroup(addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
548 .addComponent(jLabel2)
549 .addComponent(ingredientTf2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
550 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
551 .addGroup(addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
552 .addComponent(yearComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
553 .addComponent(dayComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
554 .addComponent(monthComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
555 .addComponent(jLabel4))
556 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
557 .addGroup(addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
558 .addGroup(addRecipeLayout.createSequentialGroup()
559 .addComponent(jLabel3)
560 .addGap(12, 12, 12)
561 .addComponent(instructionsTf2, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE))
562 .addGroup(addRecipeLayout.createSequentialGroup()
563 .addComponent(jLabel10)
564 .addGap(18, 18, 18)
565 .addGroup(addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
566 .addGroup(addRecipeLayout.createSequentialGroup()
567 .addComponent(appetizerRB2)
568 .addGap(12, 12, 12)
569 .addComponent(soupsRB2)
570 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
571 .addComponent(pastaRB2)
572 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
573 .addComponent(sideDishRB2)
574 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
575 .addComponent(mainDishRB2))
576 .addGroup(addRecipeLayout.createSequentialGroup()
577 .addComponent(meatRB2)
578 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
579 .addComponent(seafoodRB2)
580 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
581 .addComponent(dessertRB2)
582 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
583 .addComponent(drinksRB2)
584 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
585 .addComponent(specialRecipeRB2)))
586 .addGap(18, 18, 18)
587 .addComponent(jLabel8)
588 .addGap(18, 18, 18)
589 .addComponent(timeRequiredTf2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
590 .addGap(0, 0, Short.MAX_VALUE)))
591 .addGap(18, 18, 18)
592 .addGroup(addRecipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
593 .addComponent(saveBt)
594 .addComponent(resetBt))
595 .addGap(37, 37, 37))
596 );
597
598 tabs.addTab("Add Recipes", addRecipe);
599
600 fileMenu.setMnemonic('f');
601 fileMenu.setText("File");
602
603 openMenuItem.setMnemonic('o');
604 openMenuItem.setText("Open");
605 fileMenu.add(openMenuItem);
606
607 saveMenuItem.setMnemonic('s');
608 saveMenuItem.setText("Save");
609 fileMenu.add(saveMenuItem);
610
611 saveAsMenuItem.setMnemonic('a');
612 saveAsMenuItem.setText("Save As ...");
613 saveAsMenuItem.setDisplayedMnemonicIndex(5);
614 fileMenu.add(saveAsMenuItem);
615
616 exitMenuItem.setMnemonic('x');
617 exitMenuItem.setText("Exit");
618 exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
619 public void actionPerformed(java.awt.event.ActionEvent evt) {
620 exitMenuItemActionPerformed(evt);
621 }
622 });
623 fileMenu.add(exitMenuItem);
624
625 menuBar.add(fileMenu);
626
627 editMenu.setMnemonic('e');
628 editMenu.setText("Edit");
629
630 cutMenuItem.setMnemonic('t');
631 cutMenuItem.setText("Cut");
632 editMenu.add(cutMenuItem);
633
634 copyMenuItem.setMnemonic('y');
635 copyMenuItem.setText("Copy");
636 editMenu.add(copyMenuItem);
637
638 pasteMenuItem.setMnemonic('p');
639 pasteMenuItem.setText("Paste");
640 editMenu.add(pasteMenuItem);
641
642 deleteMenuItem.setMnemonic('d');
643 deleteMenuItem.setText("Delete");
644 editMenu.add(deleteMenuItem);
645
646 menuBar.add(editMenu);
647
648 helpMenu.setMnemonic('h');
649 helpMenu.setText("Help");
650
651 contentsMenuItem.setMnemonic('c');
652 contentsMenuItem.setText("Contents");
653 helpMenu.add(contentsMenuItem);
654
655 aboutMenuItem.setMnemonic('a');
656 aboutMenuItem.setText("About");
657 helpMenu.add(aboutMenuItem);
658
659 menuBar.add(helpMenu);
660
661 setJMenuBar(menuBar);
662
663 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
664 getContentPane().setLayout(layout);
665 layout.setHorizontalGroup(
666 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
667 .addGroup(layout.createSequentialGroup()
668 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
669 .addComponent(tabs, javax.swing.GroupLayout.PREFERRED_SIZE, 789, javax.swing.GroupLayout.PREFERRED_SIZE))
670 );
671 layout.setVerticalGroup(
672 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
673 .addComponent(tabs, javax.swing.GroupLayout.PREFERRED_SIZE, 633, javax.swing.GroupLayout.PREFERRED_SIZE)
674 );
675
676 pack();
677 }// </editor-fold>
678
679 private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
680 System.exit(0);
681 }
682
683 private void resetBtActionPerformed(java.awt.event.ActionEvent evt) {
684 nameTf2.setText("");
685 ingredientTf2.setText("");
686 instructionsTf2.setText("");
687 monthComboBox2.setSelectedIndex(0);
688 dayComboBox2.setSelectedIndex(0);
689 yearComboBox2.setSelectedIndex(0);
690 appetizerRB2.setSelected(false);
691 soupsRB2.setSelected(false);
692 specialRecipeRB2.setSelected(false);
693 pastaRB2.setSelected(false);
694 sideDishRB2.setSelected(false);
695 meatRB2.setSelected(false);
696 seafoodRB2.setSelected(false);
697 dessertRB2.setSelected(false);
698 mainDishRB2.setSelected(false);
699 drinksRB2.setSelected(false);
700 timeRequiredTf2.setText("");
701 }
702
703 private void instructionsTf2ActionPerformed(java.awt.event.ActionEvent evt) {
704
705 }
706
707 private void saveBtMouseReleased(java.awt.event.MouseEvent evt) {
708
709
710 String recipeName = nameTf2.getText();
711
712
713 String [] category = {"", "", "", "", "", "", "", "", "", ""};
714 if(appetizerRB2.isSelected()){
715 category[0] = "Appetizer";
716 }
717 if(soupsRB2.isSelected()){
718 category[1] = "Soups/Salads";
719 }
720 if(specialRecipeRB2.isSelected()){
721 category[2] = "Special Recipe";
722 }
723 if(pastaRB2.isSelected()){
724 category[3] = "Pasta";
725 }
726 if(sideDishRB2.isSelected()){
727 category[4] = "Side Dish";
728 }
729 if(meatRB2.isSelected()){
730 category[5] = "Meat/Chicken";
731 }
732 if(seafoodRB2.isSelected()){
733 category[6] = "Seafood";
734 }
735 if(dessertRB2.isSelected()){
736 category[7] = "Dessert/Bread";
737 }
738 if(mainDishRB2.isSelected()){
739 category[8] = "Main Dish";
740 }
741 if(drinksRB2.isSelected()){
742 category[9] = "Drinks";
743 }
744
745
746 String ingredient = ingredientTf2.getText();
747
748
749 String instruction = instructionsTf2.getText();
750
751
752 String month = (String) monthComboBox2.getSelectedItem();
753 String day = (String) dayComboBox2.getSelectedItem();
754 String year = (String) yearComboBox2.getSelectedItem();
755
756 String recordedDate = "" + month + "/" + day + "/" + year;
757
758 int timeRequired = Integer.parseInt(timeRequiredTf2.getText());
759
760 recipes[counter] = new RecipeClass (recipeName, category, ingredient,
761 instruction, recordedDate, timeRequired);
762 counter++;
763
764 nameTf2.setText("");
765 ingredientTf2.setText("");
766 instructionsTf2.setText("");
767 monthComboBox2.setSelectedIndex(0);
768 dayComboBox2.setSelectedIndex(0);
769 yearComboBox2.setSelectedIndex(0);
770 appetizerRB2.setSelected(false);
771 soupsRB2.setSelected(false);
772 specialRecipeRB2.setSelected(false);
773 pastaRB2.setSelected(false);
774 sideDishRB2.setSelected(false);
775 meatRB2.setSelected(false);
776 seafoodRB2.setSelected(false);
777 dessertRB2.setSelected(false);
778 mainDishRB2.setSelected(false);
779 drinksRB2.setSelected(false);
780 timeRequiredTf2.setText("");
781 }
782
783 private void searchBtMouseReleased(java.awt.event.MouseEvent evt) {
784 String findMethod = (String) findComboBox.getSelectedItem();
785
786 if (findMethod.equals("Recipe Name")){
787 SortAndSearchRecipes sortClass = new SortAndSearchRecipes();
788 int key = sortClass.searchByName(recipes, nameTf.getText());
789 if (key == -1) {
790 JOptionPane.showMessageDialog(null, "No Search Results found");
791 } else {
792 int secondCounter = 0;
793 for (int i = 0; i < recipes[i].getRecipeName().length(); i++) {
794 if (recipes[i].getRecipeName().equals(nameTf.getText())) {
795 searchListTable.setValueAt(recipes[i].getRecipeName(), i, 0);
796 searchListTable.setValueAt(recipes[i].getCategory()[0] + " " +
797 recipes[i].getCategory()[1] + " " +
798 recipes[i].getCategory()[2]+ " " +
799 recipes[i].getCategory()[3]+ " "+
800 recipes[i].getCategory()[4]+ " "+
801 recipes[i].getCategory()[5] + " " +
802 recipes[i].getCategory()[6] + " " +
803 recipes[i].getCategory()[7]+ " "+
804 recipes[i].getCategory()[8]+ " "+
805 recipes[i].getCategory()[9], i, 1);
806 searchListTable.setValueAt(recipes[i].getIngredient(), i, 2);
807 searchListTable.setValueAt(recipes[i].getInstruction(), i, 3);
808 searchListTable.setValueAt(recipes[i].getRecordedDate(), i, 4);
809 searchListTable.setValueAt(recipes[i].getTimeRequired(), i, 5);
810 secondCounter++;
811 }
812 }
813 }
814 }
815
816 if (findMethod.equals("Date Added")){
817 SortAndSearchRecipes sortClass = new SortAndSearchRecipes();
818 int key = sortClass.searchByDate(recipes, nameTf.getText());
819 if (key == -1) {
820 JOptionPane.showMessageDialog(null, "No Search Results found");
821 } else {
822 int secondCounter = 0;
823 for (int i = 0; i < recipes[i].getRecordedDate().length(); i++) {
824 if (recipes[i].getRecordedDate().equals(nameTf.getText())) {
825 searchListTable.setValueAt(recipes[i].getRecipeName(), i, 0);
826 searchListTable.setValueAt(recipes[i].getCategory()[0] + " " +
827 recipes[i].getCategory()[1] + " " +
828 recipes[i].getCategory()[2]+ " " +
829 recipes[i].getCategory()[3]+ " "+
830 recipes[i].getCategory()[4]+ " "+
831 recipes[i].getCategory()[5] + " " +
832 recipes[i].getCategory()[6] + " " +
833 recipes[i].getCategory()[7]+ " "+
834 recipes[i].getCategory()[8]+ " "+
835 recipes[i].getCategory()[9], i, 1);
836 searchListTable.setValueAt(recipes[i].getIngredient(), i, 2);
837 searchListTable.setValueAt(recipes[i].getInstruction(), i, 3);
838 searchListTable.setValueAt(recipes[i].getRecordedDate(), i, 4);
839 searchListTable.setValueAt(recipes[i].getTimeRequired(), i, 5);
840 secondCounter++;
841 }
842 }
843 }
844 }
845 }
846
847 private void nameTfActionPerformed(java.awt.event.ActionEvent evt) {
848
849 }
850
851 private void deleteBt1ActionPerformed(java.awt.event.ActionEvent evt) {
852 DefaultTableModel model = (DefaultTableModel) recipeListTable.getModel();
853
854 try {
855 int SelectedRowIndex = recipeListTable.getSelectedRow();
856 model.removeRow(SelectedRowIndex);
857 } catch(Exception ex)
858 {
859 JOptionPane.showMessageDialog(null, ex);
860 }
861 }
862
863 private void refreshListBtMouseReleased(java.awt.event.MouseEvent evt) {
864 refresh();
865 }
866
867 private void sortByNewestBtMouseReleased(java.awt.event.MouseEvent evt) {
868 sortClass.sortByNewest(recipes);
869 refresh();
870 }
871
872 private void sortByAlphabetBtMouseReleased(java.awt.event.MouseEvent evt) {
873 sortClass.sortByRecipeNameAtoZ(recipes);
874 refresh();
875 }
876
877
878 @param args
879
880 public static void main(String args[]) {
881
882
883
884
885
886 try {
887 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
888 if ("Nimbus".equals(info.getName())) {
889 javax.swing.UIManager.setLookAndFeel(info.getClassName());
890 break;
891 }
892 }
893 } catch (ClassNotFoundException ex) {
894 java.util.logging.Logger.getLogger(MainGUIForRecipes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
895 } catch (InstantiationException ex) {
896 java.util.logging.Logger.getLogger(MainGUIForRecipes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
897 } catch (IllegalAccessException ex) {
898 java.util.logging.Logger.getLogger(MainGUIForRecipes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
899 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
900 java.util.logging.Logger.getLogger(MainGUIForRecipes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
901 }
902
903
904
905
906 java.awt.EventQueue.invokeLater(new Runnable() {
907 public void run() {
908 new MainGUIForRecipes().setVisible(true);
909 }
910 });
911 }
912
913 // Variables declaration - do not modify
914 private javax.swing.JMenuItem aboutMenuItem;
915 private javax.swing.JPanel addRecipe;
916 private javax.swing.JRadioButton appetizerRB2;
917 private javax.swing.JMenuItem contentsMenuItem;
918 private javax.swing.JMenuItem copyMenuItem;
919 private javax.swing.JMenuItem cutMenuItem;
920 private javax.swing.JComboBox<String> dayComboBox2;
921 private javax.swing.JButton deleteBt1;
922 private javax.swing.JMenuItem deleteMenuItem;
923 private javax.swing.JRadioButton dessertRB2;
924 private javax.swing.JRadioButton drinksRB2;
925 private javax.swing.JMenu editMenu;
926 private javax.swing.JMenuItem exitMenuItem;
927 private javax.swing.JMenu fileMenu;
928 private javax.swing.JComboBox<String> findComboBox;
929 private javax.swing.JMenu helpMenu;
930 private javax.swing.JTextField ingredientTf2;
931 private javax.swing.JTextField instructionsTf2;
932 private javax.swing.JFrame jFrame1;
933 private javax.swing.JLabel jLabel1;
934 private javax.swing.JLabel jLabel10;
935 private javax.swing.JLabel jLabel11;
936 private javax.swing.JLabel jLabel12;
937 private javax.swing.JLabel jLabel2;
938 private javax.swing.JLabel jLabel3;
939 private javax.swing.JLabel jLabel4;
940 private javax.swing.JLabel jLabel7;
941 private javax.swing.JLabel jLabel8;
942 private javax.swing.JLabel jLabel9;
943 private javax.swing.JScrollPane jScrollPane1;
944 private javax.swing.JPanel listRecipe;
945 private javax.swing.JRadioButton mainDishRB2;
946 private javax.swing.JRadioButton meatRB2;
947 private javax.swing.JMenuBar menuBar;
948 private javax.swing.JComboBox<String> monthComboBox2;
949 private javax.swing.JTextField nameTf;
950 private javax.swing.JTextField nameTf2;
951 private javax.swing.JMenuItem openMenuItem;
952 private javax.swing.JRadioButton pastaRB2;
953 private javax.swing.JMenuItem pasteMenuItem;
954 private javax.swing.JTable recipeListTable;
955 private javax.swing.JButton refreshListBt;
956 private javax.swing.JButton resetBt;
957 private javax.swing.JMenuItem saveAsMenuItem;
958 private javax.swing.JButton saveBt;
959 private javax.swing.JMenuItem saveMenuItem;
960 private javax.swing.JRadioButton seafoodRB2;
961 private javax.swing.JButton searchBt;
962 private javax.swing.JTable searchListTable;
963 private javax.swing.JPanel searchRecipe;
964 private javax.swing.JRadioButton sideDishRB2;
965 private javax.swing.JButton sortByAlphabetBt;
966 private javax.swing.JButton sortByNewestBt;
967 private javax.swing.JRadioButton soupsRB2;
968 private javax.swing.JRadioButton specialRecipeRB2;
969 private javax.swing.JScrollPane tableScroll;
970 private javax.swing.JTabbedPane tabs;
971 private javax.swing.JTextField timeRequiredTf2;
972 private javax.swing.JComboBox<String> yearComboBox2;
973 // End of variables declaration
974
975 }
976