-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.java
3625 lines (3271 loc) · 134 KB
/
Program.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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.text.*;
//-----------------------------------------------------------------------------
// Main Program; This is the password screen that opens up on
// start-up of the application.
public class Program extends JFrame implements ActionListener
{
//Main method of program initiates the password screen
public static void main (String [] args)
{
Program EP = new Program("");
EP.FR.setVisible(true);
}
JFrame FR = new JFrame("Ecology Club - Recycling Activity Monitoring System");
Container Obj1 = getContentPane();
GridBagLayout GBL = new GridBagLayout();
GridBagConstraints GBC = new GridBagConstraints();
JMenuBar MB = new JMenuBar();
JMenu file = new JMenu("File");
JMenuItem CloseFile = new JMenuItem("Close");
Font f = new Font("Comic Sans MS", Font.BOLD, 22);
Color c = new Color(6, 69, 1);
ImageIcon logo = new ImageIcon("ClubLogo.jpg");
JLabel lbl1 = new JLabel("",logo,SwingConstants.TRAILING);
JLabel lbl2 = new JLabel("The EIS-J Ecology Club");
JLabel lblPass = new JLabel("Password:");
JButton btnSubmit = new JButton("Submit");
JButton btnForgotPass = new JButton("Forgot Password?");
JPasswordField txtPass = new JPasswordField(20);
int PassCounter = 0; //Counter for failed login attempts
int sQtionCounter = 0; //Counter for failed secret question attempts
//Constructor for the Password Screen that places components on the Frame
public Program(String str)
{
super(str);
getContentPane().setLayout(GBL);
FR.setJMenuBar(MB);
FR.add(getContentPane());
MB.add(file);
file.add(CloseFile);
GBC.fill = GridBagConstraints.BOTH;
GBC.anchor = GridBagConstraints.CENTER;
GBC.gridwidth = 3;
GBC.gridheight = 1;
GBC.gridy = 0;
GBC.gridx = 0;
GBC.insets = new Insets(10,10,10,10);
lbl2.setFont(f);
lbl2.setForeground(Color.white);
lbl2.setHorizontalAlignment(JLabel.CENTER);
GBL.setConstraints(lbl2,GBC);
getContentPane().add(lbl2);
GBC.gridy = 1;
GBC.gridheight = 3;
GBL.setConstraints(lbl1,GBC);
getContentPane().add(lbl1);
GBC.gridx = 2;
GBC.gridy = 6;
GBC.gridwidth = 1;
GBC.gridheight = 2;
GBL.setConstraints(btnSubmit,GBC);
getContentPane().add(btnSubmit);
GBC.gridx = 4;
GBC.gridy = 5;
GBC.gridwidth = 1;
GBL.setConstraints(btnForgotPass,GBC);
getContentPane().add(btnForgotPass);
txtPass.setEchoChar('*');
lblPass.setLabelFor(txtPass);
GBC.gridx = 2;
GBC.gridwidth = 3;
GBC.gridheight = 1;
GBC.gridy = 4;
GBL.setConstraints(lblPass,GBC);
lblPass.setForeground(Color.white);
getContentPane().add(lblPass);
GBC.gridy = 5;
GBC.gridwidth = 1;
GBL.setConstraints(txtPass,GBC);
getContentPane().add(txtPass);
getContentPane().setBackground(c);
FR.setExtendedState(Frame.MAXIMIZED_BOTH);
btnSubmit.addActionListener(this);
btnForgotPass.addActionListener(this);
CloseFile.addActionListener(this);
validate();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
setVisible(false);
System.exit(0);
}
});
}
// This method reads the random access file thats store the system
// security details. The password stored in the file is returned to
// the method and this is used in the actionPerformed method.
private String currentPassword()
{
//Creates object of SystemSecurity.dat file that stores the program's password
File PasswordStore = new File("SystemSecurity.dat");
//Initialises variable to store the password in the RAF
String pass = "";
//Checks if the system security file exists in the current directory
if(!PasswordStore.exists())
{
// Error beep sound
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog(this, "Error. The file that stores the password does not exist.","Error Message", JOptionPane.ERROR_MESSAGE);
System.exit(1); //Shuts down the program as a malfunction because login is not possible without the password file
return null;
}
else
{
try
{
RandomAccessFile RAF = new RandomAccessFile(PasswordStore, "r"); //Creates object to read RAF
RAF.seek(0); //Sets pointer to start of file
for(int i = 0; i < 20; i++)
{
byte letter = RAF.readByte(); //Reads each character from the first 20 characters of the file
pass = pass + (char) letter; //Adds each character from the password field of the file
}
pass = pass.trim();
RAF.close(); //Closes Random Access File
}
catch(Exception e)
{
Toolkit.getDefaultToolkit().beep(); //Error beep sound
JOptionPane.showMessageDialog(this, "An error has occured. Please contact Harris Rasheed to deal with this issue\nError Code: " + e,"Error Message", JOptionPane.ERROR_MESSAGE); //Output any errors caught
}
}
return pass; //Returns the password stored in the file
}
//-----------------------------------------------------------------
//This method reads the random access file thats store the system
//security details. The secret question's answer stored in the file
//is returned to the method and this is used in the actionPerformed method.
private String[] currentSQtionAnswer()
{
File PasswordStore = new File("SystemSecurity.dat"); //Creates an object of SystemSecurity.dat
try
{
String[] sQtion = new String[2];
RandomAccessFile RAF = new RandomAccessFile(PasswordStore, "r"); //Creates object to read Random Access File
RAF.seek(20); //Goes to the 20th position of the file where the secret question is stored
sQtion[0] = "";
for(int i = 0; i < 60; i++) //Loop reads secret question from RAF
{
byte c = RAF.readByte();
sQtion[0] += (char) c;
}
RAF.seek(80); //Goes to the 80th position where the secret answer is stored
sQtion[1] = "";
for(int i = 0; i < 20; i++) //Loop reads answer to secret question from RAF
{
byte c = RAF.readByte();
sQtion[1] += (char) c;
}
sQtion[0] = sQtion[0].trim(); //Remove whitespace after and before the secret question
sQtion[1] = sQtion[1].trim(); //Remove whitespace after and before the secret answer
RAF.close();
return sQtion; //Returns RAF secret question and answer
}
catch(Exception e)
{
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog(this, "An unexpected error occured. Please contact Harris Rasheed for more information.\nError Code: " + e,"Error Message", JOptionPane.ERROR_MESSAGE); //Output any errors caught
}
return null;
}
//-----------------------------------------------------------------
//This method is used to execute the appropriate method when the user performs an action event
public void actionPerformed(ActionEvent ae)
{
String passwd = new String(txtPass.getPassword());
if(ae.getSource()==btnSubmit)
{
if(passwd.equals(""))
{
JOptionPane.showMessageDialog(this, "Error! Please input a password.","Error Message", JOptionPane.ERROR_MESSAGE);
}
else if(passwd.equals(currentPassword())) //Condition that input password is correct
{
FR.setVisible(false); //Hides current window
menuPage MP = new menuPage(""); //Creates object of Menu class and executes constructor
MP.FR.setVisible(true); //Makes Menu Page's Frame visible
}
else
{
PassCounter++; //Adds one to the counter for the failed attempt
if(PassCounter==5) //Checks if the counter has reached five failed attempts
{
JOptionPane.showMessageDialog(this, "You have exceeded the number of login attempts available.\nThis program will now shut down.","Error Message", JOptionPane.ERROR_MESSAGE);
Toolkit.getDefaultToolkit().beep();
System.exit(0); //Exits program because of excess login attempts
}
else
{
JOptionPane.showMessageDialog(this, "The password you have input is incorrect. Please retype the correct password.","Error Message", JOptionPane.ERROR_MESSAGE);
Toolkit.getDefaultToolkit().beep();
txtPass.setText(""); //Clears the password field
txtPass.requestFocus(); //Makes the cursor focus on the password field so that the password can be retyped
}
}
}
else if(ae.getSource()==btnForgotPass)
{
String gAnswer = JOptionPane.showInputDialog(null, currentSQtionAnswer()[0],"Forgot Password", 3); //User's given secret answer
if(gAnswer.equals(null)||gAnswer.equals("")) //Tests if the given answer is blank or null
{
JOptionPane.showMessageDialog(this, "Error. Please input an answer!","Error Message", JOptionPane.ERROR_MESSAGE);
return;
}
if(gAnswer.equalsIgnoreCase(currentSQtionAnswer()[1])) //Test if the input answer is correct
{
FR.setVisible(false);
menuPage MP = new menuPage("");
MP.FR.setVisible(true);
}
else
{
Toolkit.getDefaultToolkit().beep();
sQtionCounter++; //Appends one to the secret question counter because of failed login
if(sQtionCounter == 3) //Tests when the 3 failed secret question attempts have been made
{
JOptionPane.showMessageDialog(this, "You have exceeded the number of secret question attempts available.\nThis program will now shut down.","Error Message", JOptionPane.ERROR_MESSAGE);
System.exit(0); //Exits program because of excess login attempts
}
else
{
JOptionPane.showMessageDialog(null, "Error! The answer you have input is incorrect.", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
else if(ae.getSource()==CloseFile)
{
System.exit(0); //Exits program because the close button from the menubar is pressed
}
}
}
//----------------------------------------------------------------------------------------------------------------------
//Menu Screen; This is the main menu of the program where all features of the program can be accessed through.
class menuPage extends JFrame implements ActionListener
{
JFrame FR = new JFrame("Recycling Activity Monitoring System - Main Menu");
Container Obj1 = getContentPane();
GridBagLayout GBL = new GridBagLayout();
GridBagConstraints GBC = new GridBagConstraints();
JMenuBar MB = new JMenuBar();
JMenu file = new JMenu("File");
JMenu view = new JMenu("View");
JMenu help = new JMenu("Help");
JMenu bgColour = new JMenu("Background Colour");
JMenuItem logOut = new JMenuItem("Log out");
JMenuItem Exit = new JMenuItem("Exit");
JMenuItem About = new JMenuItem("About");
ButtonGroup rbg = new ButtonGroup();
JRadioButtonMenuItem bgYellow = new JRadioButtonMenuItem("Yellow", false);
JRadioButtonMenuItem bgOrange = new JRadioButtonMenuItem("Orange", false);
JRadioButtonMenuItem bgRed = new JRadioButtonMenuItem("Red", false);
JRadioButtonMenuItem bgPink = new JRadioButtonMenuItem("Pink", false);
JRadioButtonMenuItem bgLightGreen = new JRadioButtonMenuItem("Light Green", false);
JRadioButtonMenuItem bgDarkGreen = new JRadioButtonMenuItem("Dark Green", true);
JRadioButtonMenuItem bgBlue = new JRadioButtonMenuItem("Dark Blue", false);
JRadioButtonMenuItem bgCyan = new JRadioButtonMenuItem("Cyan", false);
JRadioButtonMenuItem bgMagenta = new JRadioButtonMenuItem("Magenta", false);
JRadioButtonMenuItem bgWhite = new JRadioButtonMenuItem("White", false);
JRadioButtonMenuItem bgLightGray = new JRadioButtonMenuItem("Light Gray", false);
JRadioButtonMenuItem bgDarkGray = new JRadioButtonMenuItem("Dark Gray", false);
JRadioButtonMenuItem bgBlack = new JRadioButtonMenuItem("Black", false);
JButton btnThursRecycQuota = new JButton("Thursday Recycling Quota"); //Create Menu Screen Buttons
JButton btnRecyAttendanceReport = new JButton("Recycler Attendance Report");
JButton btnRecyActivityReport = new JButton("Recycling Activity Report");
JButton btnRecyRegist = new JButton("Recycler Registration");
JButton btnRecyMonCrit = new JButton("Recycler of the Month Candidate Criteria");
JButton btnTeacherClass = new JButton("Teachers & Classrooms Plan");
JButton btnFormClass = new JButton("Form Class Locations");
JButton btnSecuritySett = new JButton("Security Settings");
JButton btnLogOut = new JButton("Log out");
JLabel lblTitle = new JLabel("Menu");
Color c = new Color(6,69,1);
Font f = new Font("Comic Sans MS", Font.BOLD, 28);
//-----------------------------------------------------------------
//Constructor for the Menu Screen that places components on the Frame
public menuPage(String str)
{
super(str);
getContentPane().setLayout(GBL);
FR.setJMenuBar(MB);
FR.add(getContentPane());
GBC.fill = GridBagConstraints.BOTH;
GBC.anchor = GridBagConstraints.CENTER;
GBC.gridwidth = 2;
GBC.gridheight = 2;
GBC.gridy = 1;
GBC.gridx = 1;
GBC.ipady = 20;
GBC.insets = new Insets(10,10,10,10);
lblTitle.setFont(f);
lblTitle.setHorizontalAlignment(JLabel.CENTER);
lblTitle.setForeground(Color.white);
GBL.setConstraints(lblTitle,GBC);
getContentPane().add(lblTitle);
GBC.gridy = 3;
GBL.setConstraints(btnThursRecycQuota,GBC);
getContentPane().add(btnThursRecycQuota);
GBC.gridy = 5;
GBL.setConstraints(btnRecyAttendanceReport,GBC);
getContentPane().add(btnRecyAttendanceReport);
GBC.gridy = 7;
GBL.setConstraints(btnRecyActivityReport,GBC);
getContentPane().add(btnRecyActivityReport);
GBC.gridy = 9;
GBL.setConstraints(btnRecyRegist,GBC);
getContentPane().add(btnRecyRegist);
GBC.gridy = 11;
GBL.setConstraints(btnRecyMonCrit,GBC);
getContentPane().add(btnRecyMonCrit);
GBC.gridy = 13;
GBL.setConstraints(btnTeacherClass,GBC);
getContentPane().add(btnTeacherClass);
GBC.gridy = 15;
GBL.setConstraints(btnFormClass,GBC);
getContentPane().add(btnFormClass);
GBC.gridy = 17;
GBC.gridheight = GridBagConstraints.RELATIVE;
GBL.setConstraints(btnSecuritySett,GBC);
getContentPane().add(btnSecuritySett);
GBC.gridy = 25;
GBC.gridx = 2;
GBC.weighty = 1;
GBC.gridheight = GridBagConstraints.REMAINDER;
GBL.setConstraints(btnLogOut,GBC);
getContentPane().add(btnLogOut);
MB.add(file);
MB.add(view);
MB.add(help);
file.add(logOut);
file.add(Exit);
view.add(bgColour);
help.add(About);
view.add(bgColour);
bgColour.add(bgYellow); //Add Background Colour Radio Buttons
rbg.add(bgYellow); //Add Radio Buttons to Button Group
bgColour.add(bgOrange);
rbg.add(bgOrange);
bgColour.add(bgRed);
rbg.add(bgRed);
bgColour.add(bgPink);
rbg.add(bgPink);
bgColour.add(bgLightGreen);
rbg.add(bgLightGreen);
bgColour.add(bgDarkGreen);
rbg.add(bgDarkGreen);
bgColour.add(bgCyan);
rbg.add(bgCyan);
bgColour.add(bgBlue);
rbg.add(bgBlue);
bgColour.add(bgMagenta);
rbg.add(bgMagenta);
bgColour.add(bgWhite);
rbg.add(bgWhite);
bgColour.add(bgLightGray);
rbg.add(bgLightGray);
bgColour.add(bgDarkGray);
rbg.add(bgDarkGray);
bgColour.add(bgBlack);
rbg.add(bgBlack);
file.setMnemonic('f'); //Add Keyboard Shortcut Keys
view.setMnemonic('v');
Exit.setMnemonic('x');
logOut.setMnemonic('o');
bgColour.setMnemonic('b');
bgYellow.setMnemonic('y');
bgOrange.setMnemonic('o');
bgRed.setMnemonic('r');
bgPink.setMnemonic('p');
bgLightGreen.setMnemonic('l');
bgDarkGreen.setMnemonic('g');
bgBlue.setMnemonic('u');
bgCyan.setMnemonic('c');
bgMagenta.setMnemonic('m');
bgWhite.setMnemonic('w');
bgLightGray.setMnemonic('a');
bgDarkGray.setMnemonic('d');
bgBlack.setMnemonic('b');
getContentPane().setBackground(c);
FR.setExtendedState(Frame.MAXIMIZED_BOTH);
bgYellow.addActionListener(this);
bgOrange.addActionListener(this);
bgRed.addActionListener(this);
bgPink.addActionListener(this);
bgLightGreen.addActionListener(this);
bgDarkGreen.addActionListener(this);
bgBlue.addActionListener(this);
bgCyan.addActionListener(this);
bgMagenta.addActionListener(this);
bgWhite.addActionListener(this);
bgLightGray.addActionListener(this);
bgDarkGray.addActionListener(this);
bgBlack.addActionListener(this);
btnThursRecycQuota.addActionListener(this);
btnRecyAttendanceReport.addActionListener(this);
btnRecyActivityReport.addActionListener(this);
btnRecyRegist.addActionListener(this);
btnRecyMonCrit.addActionListener(this);
btnTeacherClass.addActionListener(this);
btnFormClass.addActionListener(this);
btnSecuritySett.addActionListener(this);
btnLogOut.addActionListener(this);
About.addActionListener(this);
logOut.addActionListener(this);
Exit.addActionListener(this);
validate();
addWindowListener(new WindowAdapter() //Activate Window 'X' Button
{
public void windowClosing(WindowEvent we)
{
setVisible(false);
System.exit(0);
}
});
}
//-----------------------------------------------------------------
//This method is used to execute the appropriate method when the user performs an action event
public void actionPerformed(ActionEvent ae)
{
if(bgYellow.isSelected()==true) //ActionListener checks if the user has chosen a yellow background colour
{
getContentPane().setBackground(Color.yellow); //The background colour changes to yellow
}
else if(bgOrange.isSelected()==true)
{
getContentPane().setBackground(Color.orange);
}
else if(bgRed.isSelected()==true)
{
getContentPane().setBackground(Color.red);
}
else if(bgPink.isSelected()==true)
{
getContentPane().setBackground(Color.pink);
}
else if(bgLightGreen.isSelected()==true)
{
getContentPane().setBackground(Color.green);
}
else if(bgDarkGreen.isSelected()==true)
{
getContentPane().setBackground(c);
}
else if(bgWhite.isSelected()==true)
{
getContentPane().setBackground(Color.white);
}
else if(bgBlue.isSelected()==true)
{
getContentPane().setBackground(Color.blue);
}
else if(bgCyan.isSelected()==true)
{
getContentPane().setBackground(Color.cyan);
}
else if(bgMagenta.isSelected()==true)
{
getContentPane().setBackground(Color.magenta);
}
else if(bgBlack.isSelected()==true)
{
getContentPane().setBackground(Color.black);
}
else if(bgDarkGray.isSelected()==true)
{
getContentPane().setBackground(Color.darkGray);
}
else if(bgLightGray.isSelected()==true)
{
getContentPane().setBackground(Color.lightGray);
}
if(ae.getSource()==btnThursRecycQuota)
{
FR.setVisible(false);
thursdayRecyclingQuota TRQ = new thursdayRecyclingQuota("");
TRQ.FR.setVisible(true);
}
if(ae.getSource()==btnRecyAttendanceReport)
{
FR.setVisible(false);
recyclerAttendanceReport RAttR = new recyclerAttendanceReport("");
RAttR.FR.setVisible(true);
}
if(ae.getSource()==btnRecyActivityReport)
{
FR.setVisible(false);
recyclingActivityReport RActR = new recyclingActivityReport("");
RActR.FR.setVisible(true);
}
if(ae.getSource()==btnRecyRegist)
{
FR.setVisible(false);
recyclerRegistration RR = new recyclerRegistration("");
RR.FR.setVisible(true);
}
if(ae.getSource()==btnRecyMonCrit)
{
FR.setVisible(false);
RoMCriterion RoMC = new RoMCriterion("");
RoMC.FR.setVisible(true);
}
if(ae.getSource()==btnTeacherClass)
{
FR.setVisible(false);
teacherClassPlan TCP = new teacherClassPlan("");
TCP.FR.setVisible(true);
}
if(ae.getSource()==btnFormClass)
{
FR.setVisible(false);
formClassroomLocation FCL = new formClassroomLocation("");
FCL.FR.setVisible(true);
}
if(ae.getSource()==btnSecuritySett)
{
FR.setVisible(false);
securitySett SS = new securitySett("");
SS.FR.setVisible(true);
}
if(ae.getSource()==About)
{
JOptionPane.showMessageDialog(this, "Recycling Activity Monitoring System Version 1.0\nDeveloper: Harris Rasheed\nDate Developed: 13th March 2010", "About", JOptionPane.INFORMATION_MESSAGE);
}
if(ae.getSource()==logOut||ae.getSource()==btnLogOut)
{
FR.setVisible(false);
Program EP = new Program("");
EP.FR.setVisible(true);
}
if(ae.getSource()==Exit)
{
System.exit(0);
}
}
}
//----------------------------------------------------------------------------------------------------------------------
//Thursday Recycling Quota Menu Screen; This is the Thursday Recycling Quota Menu screen where the Morning Skip Monitor
//input screen can be accessed or the Lunch Collection Rounds input screen.
class thursdayRecyclingQuota extends JFrame implements ActionListener
{
JFrame FR = new JFrame("Recycling Activity Monitoring System - Thursday Recycling Quota");
Container Obj1 = getContentPane();
GridBagLayout GBL = new GridBagLayout();
GridBagConstraints GBC = new GridBagConstraints();
JMenuBar MB = new JMenuBar();
JMenu file = new JMenu("File");
JMenuItem logOut = new JMenuItem("Log out");
JMenuItem Exit = new JMenuItem("Exit");
JButton MorningSkipbtn = new JButton("Morning Skip Monitor");
JButton LunchCollbtn = new JButton("Lunch Collection Rounds");
JButton btnBack = new JButton("Back");
JLabel lblThursRecycQuota = new JLabel("Thursday Recycling Quota");
Color c = new Color(6,69,1);
Font f = new Font("Comic Sans MS", Font.BOLD, 22);
//-----------------------------------------------------------------
//Constructor for the Thursday Recycling Quota Screen that places components on the Frame
public thursdayRecyclingQuota(String str)
{
super(str);
FR.setJMenuBar(MB);
MB.add(file);
file.add(logOut);
file.add(Exit);
getContentPane().setLayout(GBL);
FR.add(Obj1);
GBC.fill = GridBagConstraints.BOTH;
GBC.anchor = GridBagConstraints.PAGE_START;
GBC.gridwidth = 2;
GBC.gridheight = 2;
GBC.gridy = 1;
GBC.gridx = 1;
GBC.insets = new Insets(10,10,10,10);
GBC.fill = GridBagConstraints.VERTICAL;
GBL.setConstraints(lblThursRecycQuota,GBC);
lblThursRecycQuota.setFont(f);
lblThursRecycQuota.setHorizontalAlignment(JLabel.CENTER);
lblThursRecycQuota.setForeground(Color.white);
getContentPane().add(lblThursRecycQuota);
GBC.anchor = GridBagConstraints.CENTER;
GBC.gridy = 3;
GBC.ipady = 20;
GBC.ipadx = 100;
GBL.setConstraints(MorningSkipbtn,GBC);
getContentPane().add(MorningSkipbtn);
GBC.gridy = 5;
GBL.setConstraints(LunchCollbtn,GBC);
getContentPane().add(LunchCollbtn);
GBC.gridy = 20;
GBC.anchor = GridBagConstraints.PAGE_END;
GBC.insets = new Insets(250,10,10,10);
GBL.setConstraints(btnBack,GBC);
getContentPane().add(btnBack);
getContentPane().setBackground(c);
FR.setExtendedState(Frame.MAXIMIZED_BOTH);
MorningSkipbtn.addActionListener(this);
LunchCollbtn.addActionListener(this);
logOut.addActionListener(this);
Exit.addActionListener(this);
btnBack.addActionListener(this);
validate();
}
//-----------------------------------------------------------------
//This method is used to execute the appropriate method when the user performs an action event
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==MorningSkipbtn)
{
FR.setVisible(false);
morningSkipMonitor MSM = new morningSkipMonitor("");
MSM.FR.setVisible(true);
}
if(ae.getSource()==LunchCollbtn)
{
FR.setVisible(false);
lunchCollRounds LCR = new lunchCollRounds("");
LCR.FR.setVisible(true);
}
if(ae.getSource()==btnBack)
{
FR.setVisible(false);
menuPage MP = new menuPage("");
MP.FR.setVisible(true);
}
if(ae.getSource()==logOut)
{
FR.setVisible(false);
Program EP = new Program("");
EP.FR.setVisible(true);
}
if(ae.getSource()==Exit)
{
System.exit(0);
}
}
}
//----------------------------------------------------------------------------------------------------------------------
//Morning Skip Monitor Screen; This is the screen where the user can input data
//collected by the Recycling Skip Supervisor on Thursday Mornings
class morningSkipMonitor extends JFrame implements ActionListener
{
JFrame FR = new JFrame("Recycling Activity Monitoring System - Morning Skip Monitor");
Container Obj1 = getContentPane();
GridBagLayout GBL = new GridBagLayout();
GridBagConstraints GBC = new GridBagConstraints();
JMenuBar MB = new JMenuBar();
JMenu file = new JMenu("File");
JMenuItem logOut = new JMenuItem("Log out");
JMenuItem exit = new JMenuItem("Exit");
JButton save = new JButton("Save");
JButton cancel = new JButton("Cancel");
JLabel lblMorningSkip = new JLabel("Morning Skip Monitor");
JLabel lblDate = new JLabel("Date: ");
JTextField txtDate = new JTextField(10);
Color c = new Color(6,69,1);
Font f = new Font("Comic Sans MS", Font.BOLD, 26);
Object records[][] = new Object[38][2];
String[] colNames = {"Form Class", "Points"};
JTable table = new JTable(records(38), colNames);
JScrollPane scroll = new JScrollPane(table);
public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
//-----------------------------------------------------------------
//Constructor for the Morning Skip Monitor Screen that places components on the Frame
public morningSkipMonitor(String str)
{
super(str);
FR.setJMenuBar(MB);
MB.add(file);
file.add(logOut);
file.add(exit);
getContentPane().setLayout(GBL);
FR.add(Obj1);
GBC.fill = GridBagConstraints.BOTH;
GBC.anchor = GridBagConstraints.CENTER;
GBC.gridwidth = 2;
GBC.gridy = 1;
GBC.gridx = 1;
GBC.insets = new Insets(10,10,10,10);
GBL.setConstraints(lblMorningSkip,GBC);
lblMorningSkip.setFont(f);
lblMorningSkip.setHorizontalAlignment(JLabel.CENTER);
lblMorningSkip.setForeground(Color.white);
getContentPane().add(lblMorningSkip);
GBC.gridy = 2;
GBC.gridwidth = 1;
GBL.setConstraints(lblDate,GBC);
lblDate.setForeground(Color.white);
lblDate.setLabelFor(txtDate);
getContentPane().add(lblDate);
GBC.gridx = 2;
GBL.setConstraints(txtDate,GBC);
getContentPane().add(txtDate);
txtDate.setText(systemDateSet());
GBC.gridy = 4;
GBC.gridx = 1;
GBC.gridwidth = 2;
GBL.setConstraints(scroll,GBC);
getContentPane().add(scroll);
GBC.gridy = 10;
GBC.ipady = 20;
GBC.ipadx = 100;
GBL.setConstraints(save,GBC);
getContentPane().add(save);
GBC.gridy = 12;
GBL.setConstraints(cancel,GBC);
getContentPane().add(cancel);
getContentPane().setBackground(c);
FR.setExtendedState(Frame.MAXIMIZED_BOTH);
save.addActionListener(this);
exit.addActionListener(this);
logOut.addActionListener(this);
cancel.addActionListener(this);
validate();
}
//-----------------------------------------------------------------
//This method creates a 2D array with one column blank and the second column filled
//with ones as the default points value and the blank column available for input. This
//is used for JTable initialisation. The first parameter is the number of rows in the table
protected String[][] records(int length)
{
String records[][] = new String[length][2];
for(int i = 0; i < length; i++)
{
records[i][1] = "1";
records[i][0] = "";
}
return records;
}
//-----------------------------------------------------------------
//This method finds the system date and returns the string in the format "DD/MM/YYYY"
protected static String systemDateSet()
{
Calendar cal = Calendar.getInstance(); //Access calendar object from utility library
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); //Creates an object of the format
String a = sdf.format(cal.getTime()); //Retrieves time
return (a.substring(8,10) + "/" + a.substring(5,7) + "/" + a.substring(0,4)); //Returns date part of the string
}
//-----------------------------------------------------------------
//This method is used to reference the location of each form class. This part of the
//system is now automated.
private String[][] referenceFormLocation(String[][] tableData, int rows)
{
try
{
String problemReferences = ""; //problemReferences is used to store records that could not be referenced
File file = new File("FormClassroomLocation.txt"); //Creates an object of the File
RandomAccessFile RAF = new RandomAccessFile(file, "r"); //Creates an object of the Random Access File
int recordSize = 13; //The size of each record in the random access file is 13 characters
for(int c = 0; c < rows; c++) //First loop iterates each array index
{
boolean found = false; //Sets flag to false. This variable is used to identify problem input and reject them
int length = tableData[c][0].length(); //Finds length of the string stored in the table current index
int j = 0; //Loop counter
while(j < tableData[c][0].length()) //Analyses string until
{
if(tableData[c][0].substring(j, j+1).equals("(")) //Checks if the user has input form classes in full form; 7A(MC) opposed to just 7A
{
tableData[c][0] = tableData[c][0].substring(0, j); //Removes the latter part if full form has been used
break; //Terminate loop
}
j++; //Positive iteration to counter
}
RAF.seek(0); //Goes to the beginning of the file
for(int i = 0; i < 38; i++) //Second loop iterates the record number being searched in the file
{
if(tableData[c][0] == null) //Tests if the index in the array storing the table data is blank
{
break; //Terminates the loop if the table is blank
}
String currentLine = "", sCurrentLine = ""; //currentLine will store each record on each loop and sCurrentLine will look at certain fields of each record
RAF.seek(i * recordSize); //File pointer goes to the beginning of the each record on every loop
for(int ct = 0; ct < recordSize; ct++) //Reads each character of a record one by one
{
byte b = RAF.readByte(); //Read one character
currentLine += (char) b; //Convert to character from byte
}
sCurrentLine = currentLine.substring(0,3); //Reads first part of record
if((sCurrentLine.substring(2,3)).equals("(")) //Tests if the first field is meant to be two characters long; 7A opposed to 13A
{
sCurrentLine = currentLine.substring(0,2); //Takes the first two characters of the record
}
if(tableData[c][0].equalsIgnoreCase(sCurrentLine)) //Checks if the reference in the table and file match
{
tableData[c][0] = (currentLine.substring(8,13)).trim(); //Assigns reference file data to table array
found = true; //Activates found flag
break; //Terminates loop when the record and table data is matched
}
}
if(!found)
{
problemReferences += tableData[c][0] + " "; //Adds any input problems
tableData[c][0] = ""; //Clears problem index field
}
}
RAF.close(); //Closes the Random Access File
if(!problemReferences.equals("")) //Tests if there were no problems
{
JOptionPane.showMessageDialog(this, "The following classrooms could not be processed because they do not exist.\n" + problemReferences,"Error Message", JOptionPane.WARNING_MESSAGE); //Outputs problem input
}
return tableData; //Returns array
}
catch(FileNotFoundException e)
{
Toolkit.getDefaultToolkit().beep(); //Makes error sound
JOptionPane.showMessageDialog(this, "The FormClassroomLocation.txt notepad file is missing from the current directory. This process cannot function without this file.\nError Code: " + e,"File is Missing!", JOptionPane.ERROR_MESSAGE); //Output any error if a file is not found
}
catch(Exception e)
{
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog(this, "An error has occured. Please contact Harris Rasheed to deal with this issue\nError Code: " + e,"Error Message", JOptionPane.ERROR_MESSAGE); //Output any errors caught
}
return null;
}
//-----------------------------------------------------------------
//This method is used to store recycling statistics information. It updates existing
//data in the random access file. The first parameter is the array with records to
//be stored and the second parameter is the number of rows in the 2D array. This
//method finds the desired record to be updated, processes it and the moves it to
//the end of the file which allows the next search to be executed faster.
public void storeRecyStats(String[][] tableData, int rows)
{
try
{
File file = new File("RecyclingActivityStats.txt"); //Creates object of file
RandomAccessFile RAF = new RandomAccessFile(file, "rw"); //Creates object of Random Access File
int recordSize = 8; //The size of each record in the random access file is 8 characters
int records = (int)(RAF.length())/recordSize; //Calculates the number of records in the random access file
String errorStorage = "| - "; //Stores erroneous input data
boolean found = false; //Creates flag
for(int c = 0; c < rows; c++)
{
for(int i = 0; i < records; i++)
{
String line = "";
RAF.seek(i * recordSize);
for(int ct = 0; ct < recordSize; ct++)
{
byte b = RAF.readByte();
line += (char)b;
}
String roomNo = (line.substring(0,5)).trim();
int points = Integer.parseInt((line.substring(5,8)).trim());
if(roomNo.equalsIgnoreCase(tableData[c][0])) //Checks if the String is equal to the delete parameter
{
RAF.seek((records - 1) * (recordSize)); //File pointer looks at the last record
byte[] ba = new byte[recordSize]; //Creates array with the size of one record
RAF.readFully(ba); //Reads entire line and places it in the array
RAF.seek(i * recordSize); //File pointer looks at the place where the record was found
RAF.write(ba); //Overwrites the record location with the last record since it is to be deleted
RAF.setLength(((records - 1)* (recordSize))); //Truncates file and removes the last record from the end of the file which has been moved to the deleted record's space
RAF.seek(RAF.length()); //File pointer looks at the end of the file
for(int a = roomNo.length(); a < 5; a++) //Adds spacing to the room number field so that the record size is always of a set length
{
roomNo = roomNo + " ";
}
points += Integer.parseInt(tableData[c][1]); //Adds points to points field in the record
String StrPoints = Integer.toString(points); //Converts points number to string
for(int a = StrPoints.length(); a < 3; a++) //Adds spacing to the points field so that the record size is always of a set length
{
StrPoints = StrPoints + " ";
}
RAF.writeBytes(roomNo + StrPoints); //Writes the room number and points fields together as a record to the file
found = true; //Activates flag
break; //Terminates loop
}
}