-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfamilyTreeManagement.java
More file actions
1979 lines (1664 loc) · 98.9 KB
/
familyTreeManagement.java
File metadata and controls
1979 lines (1664 loc) · 98.9 KB
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 javax.swing.*; // import package
import java.awt.*;// import package
import java.awt.event.*;// import package
import java.io.File;// import package
import java.io.FileInputStream;// import package
import java.io.FileOutputStream;// import package
import java.io.IOException;// import package
import java.io.ObjectInputStream;// import package
import java.io.ObjectOutputStream;// import package
import javax.swing.event.TreeSelectionEvent;// import package
import javax.swing.event.TreeSelectionListener;// import package
import javax.swing.filechooser.FileNameExtensionFilter;// import package
import javax.swing.text.AttributeSet;// import package
import javax.swing.text.BadLocationException;// import package
import javax.swing.tree.DefaultMutableTreeNode;// import package
import javax.swing.text.PlainDocument;// import package
/*
Title : family Tree management program.
Author : Aung Aye Than
Date : 29th March 2018.
Filename : familyTreeManagement.java
Version : 1.0
Purpose of the program is to manage person family tree and display information of the family member which are included in the family-tree.
For the input condition, user have to enter numbers only for street number and postcode input, and user have to enter either male or female for the gender input.
Furthermore, there is the word input limitations that user can only enter only 28 words, and 11 words limitation for the numbers input.
For the expected output will be depending on the input data that user has been saved and submitted. Every output data will be shown on the view mode function.
*/
class familyTreemanagement extends JFrame
{
Container newContainers = getContentPane(); // inplementing container
JPanel menuPanel,leftPanel, rightPanel; //Declaring the JPanel variable as global variable
JButton addTreeButton, loadTreeButton, submitbutton, cancelButton,saveTreeButton,HomeButton,managePerson; //Declaring the JButton variable as global variable
JLabel firstnameLabel,surnameBirthLabel,surnameMarriageLabel, GenderLabel, paragraphLabel,addressLabel, address_StreetNameLabel,
address_SuburbLabel,addressPostcodeLabel,fatherLabel,motherLabel,SpouseLabel,childrenLabel,displayLabel,HomeLabel,
rightLabel; //Declaring the JLabel variable as global variable
JTextField firstname,surnameBirth, surnameMarriage,Gender,address_StreetNo,address_StreetName,address_Suburb,addressPostcode,father,mother,Spouse,children,
personInput, personInput2; //Declaring the JTextField variable as global variable
JTree tree; //Declaring the JTree variable as global variable
JTextArea Paragraph;
JSplitPane splitPane; //Declaring the JSplitPane variable as global variable
JScrollPane rightScrollPane,leftScrollPane; //Declaring the JScrollPane variable as global variable
JComboBox relativelist;//Declaring the JComboBox variable as global variable
person personData;
boolean personInputCheck = false;//Declaring and initialising variable as boolean as false
boolean motherDatacheck = false;//Declaring and initialising variable as boolean as false
boolean fatherDatacheck = false;//Declaring and initialising variable as boolean as false
boolean spouseDatacheck = false;//Declaring and initialising variable as boolean as false
boolean childspouseDatacheck = false;//Declaring and initialising variable as boolean as false
class ShowAddObjListener implements ActionListener //action listener to perform when certain event occurs
{
public void actionPerformed( ActionEvent e )
{
if (personInputCheck ==true) //if there is previous data in the program
{
int answer = JOptionPane.showConfirmDialog(leftPanel, "There is previous person data. Proceed to add new data without saving will lose previous data\nContinue?","Warning",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); //pop-up yes/no question to ask user about decision
if (answer == JOptionPane.YES_OPTION) //if user decided to continue
{
AddUserDetail();//proceed to start over new person creation
} else if (answer == JOptionPane.NO_OPTION) //if user decided not to continue
{
JOptionPane.showMessageDialog(leftPanel, "Please make sure to save previous data before adding a new data"); //pop-up message to tell user to save
}
else if (answer == JOptionPane.CLOSED_OPTION) //if user close the message box
{
//do nothing
}
}
else
{
AddUserDetail(); //proceed to create new person if there is no previous data
}
}
}
class cancelObjListener implements ActionListener //action listener for cancel button
{
public void actionPerformed (ActionEvent e)//action listener for cancel button
{
AddUserDetail(); // invoking method
}
}
class cancelEdit implements ActionListener //action listener for cancel button in loadData method
{
public void actionPerformed(ActionEvent e)
{
loadData(personData);// invoking method
}
}
class saveObjListener implements ActionListener //action listener for save button
{
public void actionPerformed(ActionEvent e)
{
saveTreeFile(); // invoking method
}
}
class showLoadObjListener implements ActionListener //action listener for load tree button
{
public void actionPerformed (ActionEvent e)
{
openfile(); //invoking method
}
}
class submitObjListener implements ActionListener //action listener for submit button in add user detail method
{
public void actionPerformed (ActionEvent e)
{
createData(); //invoking method
}
}
class editbuttonObjListener implements ActionListener //action listener for edit button in add user detail method
{
public void actionPerformed (ActionEvent e)
{
try // try-catch block to catch exception
{
//JTree tree = (JTree) e.getSource();
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();//getting last selected node of user selected
Object selectedObject = selectedNode.getUserObject();
editGUI((person)selectedObject); //invoking method and cast it to person object
}
catch(NullPointerException| ClassCastException z) // proceed when there is null pointer exception
{
JOptionPane.showMessageDialog(rightPanel, "Please select person from tree that you would like to edit"); //prompt dialog to show when there is exception
}
}
}
class relativeButtionListener implements ActionListener //action listener for choose relative
{
public void actionPerformed (ActionEvent e)
{
addrelative(); //invoking method
}
}
class SelectionListener implements TreeSelectionListener //tree selection listener for tree to know what user select
{
public void valueChanged (TreeSelectionEvent e)
{
JTree tree = (JTree) e.getSource();
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();//getting last selected node of user selected
if (selectedNode == null)
{
return;
}
try
{
Object selectedObject = selectedNode.getUserObject();
loadData((person)selectedObject);
}
catch(ClassCastException k)
{
}
}
}
class relativeObjectListener implements ActionListener //action listener for submit relative data
{
public void actionPerformed (ActionEvent e)
{
try // try-catch block to catch exception
{
submitrelativedata(); //invoking method
}
catch(NullPointerException z) // proceed when there is null pointer exception
{
JOptionPane.showMessageDialog(rightPanel, "Please select person from tree that you would like to add relative data");//prompt dialog to show when there is exception
}
}
}
class saveChangesObjListener implements ActionListener//action listener for submit changes in edit data
{
public void actionPerformed(ActionEvent e)
{
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
try
{
Object selectedObject = selectedNode.getUserObject();
saveeditChanges((person)selectedObject);//invoking method
}
catch(ClassCastException k)
{
//do nothing
}
}
}
public class JTextFieldLimit extends PlainDocument //class that will perform the input word count limitation
{
private int limitamount; //set variable as int
JTextFieldLimit(int limit)
{
super();
this.limitamount = limit; // initialising limit amount
}
public void insertString( int offset, String string, AttributeSet attribute ) throws BadLocationException
{
if (string == null) //if there is no input inside
{
return;
}
if ((getLength() + string.length()) <= limitamount)
{
super.insertString(offset, string, attribute);
}
}
}
familyTreemanagement() //class name
{
super("Family Tree Management Program"); // frame name
setExtendedState(familyTreemanagement.MAXIMIZED_BOTH); //setting size to maximum
menuPanel = new JPanel(); menuPanel.setBackground(Color.WHITE); //creating new JPanel
leftPanel = new JPanel(); leftPanel.setBackground(Color.WHITE);//creating new JPanel
rightPanel = new JPanel(); rightPanel.setBackground(Color.LIGHT_GRAY);//creating new JPanel
leftScrollPane = new JScrollPane();//creating new JScrollPane
rightScrollPane = new JScrollPane();//creating new JScrollPane
splitPane = new JSplitPane(); //creating new JScrollPane
splitPane.setRightComponent(rightPanel); //setting right component for rightpanel
splitPane.setLeftComponent(leftPanel);//setting left component for leftpanel
splitPane.setResizeWeight(.5d);//setting a place to locate for spliting left and right
newContainers.setLayout(new BorderLayout());//setting layout for container
newContainers.add(menuPanel, BorderLayout.NORTH);
newContainers.add(splitPane,BorderLayout.CENTER);
MenuOption(); //invoking method
addWindowListener //action listener when closing frame
( new WindowAdapter()
{ public void windowClosing( WindowEvent e )
{ System.exit(0); }
}
);
}
void MenuOption() //method to show menu option
{
leftPanel.removeAll();//clearing all last data that is added to left panel
rightPanel.removeAll();//clearing all last data that is added to right panel
loadTreeButton = new JButton("Load Tree"); // implementing new button and named as load tree
addTreeButton = new JButton("Create New Tree");// implementing new button and named as Create New tree
saveTreeButton = new JButton ("Save Tree");// implementing new button and named as Save tree
menuPanel.setLayout(new GridLayout(0,3)); //set layout for menu panel
JLabel menulabel = new JLabel("Welcome to Family Tree Program"); //creating new label
menulabel.setFont(menulabel.getFont().deriveFont(Font.BOLD, 17f));// setting label font as bold
menuPanel.add(new JLabel(""));// adding label to menupanel to display on the panel
menuPanel.add(menulabel);// adding label to menupanel to display on the panel
menuPanel.add(new JLabel(""));// adding label to menupanel to display on the panel
menuPanel.add(addTreeButton);// adding button to menupanel to display on the panel
menuPanel.add(loadTreeButton);// adding button to menupanel to display on the panel
menuPanel.add(saveTreeButton);// adding button to menupanel to display on the panel
addTreeButton.addActionListener(new ShowAddObjListener()); // implementing actionlistener for button
loadTreeButton.addActionListener(new showLoadObjListener());// implementing actionlistener for button
saveTreeButton.addActionListener(new saveObjListener());// implementing actionlistener for button
}
void AddUserDetail()//method to create new person tree
{
leftPanel.removeAll();//clearing all last data that is added to left panel
rightPanel.removeAll();//clearing all last data that is added to right panel
leftPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
JLabel createDatalabel = new JLabel("Create FamilyTree"); //implementing new label
createDatalabel.setFont(createDatalabel.getFont().deriveFont(Font.BOLD, 17f)); // setting label size and font as bold
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 0;
leftPanel.add(createDatalabel,c);// adding label in leftPanel to display on the panel
JLabel personal = new JLabel("Person Information");//implementing new label
personal.setFont(personal.getFont().deriveFont(Font.BOLD, 16f));// setting label size and font as bold
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 1;
leftPanel.add(personal,c);// adding label in leftPanel to display on the panel
firstnameLabel = new JLabel("Name: "); //creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 2;
leftPanel.add(firstnameLabel,c);// adding label in leftPanel to display on the panel
firstname = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 3;
c.gridy = 2;
leftPanel.add(firstname,c);// adding label in leftPanel to display on the panel
firstname.setDocument(new JTextFieldLimit(28));
surnameBirthLabel = new JLabel ("Surname: ");
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 3;
leftPanel.add(surnameBirthLabel,c);
surnameBirth = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 3;
c.gridy = 3;
leftPanel.add(surnameBirth,c);
surnameBirth.setDocument(new JTextFieldLimit(28));
surnameMarriageLabel = new JLabel ("Maiden Name: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 4;
leftPanel.add(surnameMarriageLabel,c);
surnameMarriage = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 3;
c.gridy = 4;
leftPanel.add(surnameMarriage,c);
surnameMarriage.setDocument(new JTextFieldLimit(28));
GenderLabel = new JLabel ("Gender: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 5;
leftPanel.add(GenderLabel,c);
Gender = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 3;
c.gridy = 5;
leftPanel.add(Gender,c);
Gender.setDocument(new JTextFieldLimit(28));
paragraphLabel = new JLabel ("Life Description: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 6;
leftPanel.add(paragraphLabel,c);
Paragraph = new JTextArea(5,30);//creating new textfield to let user enter input
Paragraph.setPreferredSize(new Dimension(500, 550));
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.2;
c.gridx = 3;
c.gridy = 6;
Paragraph.setDocument(new JTextFieldLimit(28));
JScrollPane areaScrollPane = new JScrollPane(Paragraph,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
leftPanel.add(areaScrollPane,c);
JLabel addressText =new JLabel("Address Information");//implementing new label
addressText.setFont(addressText.getFont().deriveFont(Font.BOLD, 16f));// setting label size and font as bold
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 7;
leftPanel.add(addressText,c);// adding label in leftPanel to display on the panel
addressLabel = new JLabel ("Street Number: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 8;
leftPanel.add(addressLabel,c);
address_StreetNo = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 3;
c.gridy = 8;
leftPanel.add(address_StreetNo,c);
address_StreetNo.setDocument(new JTextFieldLimit(28));
address_StreetNameLabel = new JLabel ("Street Name: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 9;
leftPanel.add(address_StreetNameLabel,c);
address_StreetName = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 3;
c.gridy = 9;
leftPanel.add(address_StreetName,c);
address_StreetName.setDocument(new JTextFieldLimit(28));
address_SuburbLabel = new JLabel ("Suburb: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 10;
leftPanel.add(address_SuburbLabel,c);
address_Suburb= new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 3;
c.gridy = 10;
leftPanel.add(address_Suburb,c);
address_Suburb.setDocument(new JTextFieldLimit(28));
addressPostcodeLabel = new JLabel ("Postcode: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 11;
leftPanel.add(addressPostcodeLabel,c);
addressPostcode = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 3;
c.gridy = 11;
leftPanel.add(addressPostcode,c);
addressPostcode.setDocument(new JTextFieldLimit(28));
submitbutton = new JButton ("Submit ");//creating new button and name it as submit for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_END;
c.weightx = 1;
c.weighty = 0;
c.gridx = 0;
c.gridy = 12;
leftPanel.add(submitbutton,c);
submitbutton.addActionListener(new submitObjListener());// adding actionlistener for submit button
cancelButton = new JButton ("Reset");//creating new button and name it as submit for cancel input
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_END;
c.weightx = 0.5;
c.weighty = 0;
c.gridx = 3;
c.gridy = 12;
leftPanel.add(cancelButton,c);
cancelButton.addActionListener(new cancelObjListener());// adding actionlistener for cancel button
rightPanel.setLayout(new GridBagLayout());// setting layout for right panel
JLabel viewLabel = new JLabel ("No family tree detected to display"); //creating new label to show information
viewLabel.setFont(viewLabel.getFont().deriveFont(Font.BOLD, 15f)); // setting label size and font as bold
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.NORTH;
c.weightx = 0.5;
c.weighty = 1;
c.insets = new Insets(10,0,0,0);
c.gridx = 0;
c.gridy = 0;
rightPanel.add(viewLabel,c);
leftPanel.setVisible(false);// setting leftpanel as false not to visible on the panel
rightPanel.setVisible(false);// setting rightPanel as false not to visible on the panel
leftPanel.setVisible(true);// setting leftpanel as true to visible on the panel
rightPanel.setVisible(true);// setting rightPanel as true to visible on the panel
}
void loadData(person personData) //method that perform as view mode to display all available person
{
leftPanel.removeAll();//removing all the previous data from left panel
leftPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
JLabel viewmodetext = new JLabel("View Mode"); //implementing new label to show information on the panel
viewmodetext.setFont(viewmodetext.getFont().deriveFont(Font.BOLD, 20f));//setting font size and bold for label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 0;
leftPanel.add(viewmodetext,c);// adding label in leftPanel to display on the panel
JLabel personal = new JLabel("Person Information");//implementing new label
personal.setFont(personal.getFont().deriveFont(Font.BOLD, 16f));// setting label size and font as bold
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 1;
leftPanel.add(personal,c);// adding label in leftPanel to display on the panel
firstnameLabel = new JLabel("Name: "); //creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 2;
leftPanel.add(firstnameLabel,c);// adding label in leftPanel to display on the panel
firstname = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 3;
c.gridy = 2;
leftPanel.add(firstname,c);// adding label in leftPanel to display on the panel
firstname.setDocument(new JTextFieldLimit(28));
surnameBirthLabel = new JLabel ("Surname: ");
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 3;
leftPanel.add(surnameBirthLabel,c);
surnameBirth = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 3;
c.gridy = 3;
leftPanel.add(surnameBirth,c);
surnameBirth.setDocument(new JTextFieldLimit(28));
surnameMarriageLabel = new JLabel ("Maiden Name: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 4;
leftPanel.add(surnameMarriageLabel,c);
surnameMarriage = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 3;
c.gridy = 4;
leftPanel.add(surnameMarriage,c);
surnameMarriage.setDocument(new JTextFieldLimit(28));
GenderLabel = new JLabel ("Gender: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 5;
leftPanel.add(GenderLabel,c);
Gender = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 3;
c.gridy = 5;
leftPanel.add(Gender,c);
Gender.setDocument(new JTextFieldLimit(28));
paragraphLabel = new JLabel ("Life Description: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 6;
leftPanel.add(paragraphLabel,c);
Paragraph = new JTextArea(5,30);//creating new textfield to let user enter input
Paragraph.setPreferredSize(new Dimension(500, 550));
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.2;
c.gridx = 3;
c.gridy = 6;
Paragraph.setDocument(new JTextFieldLimit(28));
JScrollPane areaScrollPane = new JScrollPane(Paragraph,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
leftPanel.add(areaScrollPane,c);
JLabel addressText =new JLabel("Address Information");//implementing new label
addressText.setFont(addressText.getFont().deriveFont(Font.BOLD, 16f));// setting label size and font as bold
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 7;
leftPanel.add(addressText,c);// adding label in leftPanel to display on the panel
addressLabel = new JLabel ("Street Number: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 8;
leftPanel.add(addressLabel,c);
address_StreetNo = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 3;
c.gridy = 8;
leftPanel.add(address_StreetNo,c);
address_StreetNo.setDocument(new JTextFieldLimit(28));
address_StreetNameLabel = new JLabel ("Street Name: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 9;
leftPanel.add(address_StreetNameLabel,c);
address_StreetName = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 3;
c.gridy = 9;
leftPanel.add(address_StreetName,c);
address_StreetName.setDocument(new JTextFieldLimit(28));
address_SuburbLabel = new JLabel ("Suburb: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 10;
leftPanel.add(address_SuburbLabel,c);
address_Suburb= new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 3;
c.gridy = 10;
leftPanel.add(address_Suburb,c);
address_Suburb.setDocument(new JTextFieldLimit(28));
addressPostcodeLabel = new JLabel ("Postcode: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 11;
leftPanel.add(addressPostcodeLabel,c);
addressPostcode = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 3;
c.gridy = 11;
leftPanel.add(addressPostcode,c);
addressPostcode.setDocument(new JTextFieldLimit(28));
JLabel relativeText = new JLabel("Relative Information");//implementing new label to show information on the panel
relativeText.setFont(relativeText.getFont().deriveFont(Font.BOLD, 16f));//setting font size and bold for label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 12;
leftPanel.add(relativeText,c);
fatherLabel = new JLabel ("Father : ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_START;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 13;
leftPanel.add(fatherLabel,c);
father = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_END;
c.weightx = 0.5;
c.gridx = 3;
c.gridy = 13;
father.setText(personData.getfather());//setting label text as according to object data
father.setEditable(false);//setting editable as false to not let user edit or make changes in view mode
leftPanel.add(father,c);
motherLabel = new JLabel ("Mother : ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_START;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 14;
leftPanel.add(motherLabel,c);
mother = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_END;
c.weightx = 0.5;
c.gridx = 3;
c.gridy = 14;
mother.setText(personData.getMother());//setting label text as according to object data
mother.setEditable(false);//setting editable as false to not let user edit or make changes in view mode
leftPanel.add(mother,c);
SpouseLabel = new JLabel ("Spouse :");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_START;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 15;
leftPanel.add(SpouseLabel,c);
Spouse = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_END;
c.weightx = 0.5;
c.gridx = 3;
c.gridy = 15;
Spouse.setText(personData.getspouse());//setting label text as according to object data
Spouse.setEditable(false);//setting editable as false to not let user edit or make changes in view mode
leftPanel.add(Spouse,c);
firstname.setText(personData.getFirstname());//setting label text as according to object data
firstname.setEditable(false);//setting editable as false to not let user edit or make changes in view mode
surnameBirth.setText(personData.getsurnameBirth());//setting label text as according to object data
surnameBirth.setEditable(false);//setting editable as true to let user edit or make changes in edit mode
surnameMarriage.setText(personData.getsurnameMarriage());//setting label text as according to object data
surnameMarriage.setEditable(false);//setting editable as true to let user edit or make changes in edit mode
Gender.setText(personData.getGender());//setting label text as according to object data
Gender.setEditable(false);//setting editable as true to let user edit or make changes in edit mode
Paragraph.setText(personData.getlifeDescription());//setting label text as according to object data
Paragraph.setEditable(false);//setting editable as true to let user edit or make changes in edit mode
address_StreetNo.setText(Integer.toString(personData.getaddressStreetNo()));//setting label text as according to object data
address_StreetNo.setEditable(false);//setting editable as true to let user edit or make changes in edit mode
address_StreetName.setText(personData.getaddressStreetName());//setting label text as according to object data
address_StreetName.setEditable(false);//setting editable as true to let user edit or make changes in edit mode
address_Suburb.setText(personData.getsuburb());//setting label text as according to object data
address_Suburb.setEditable(false);//setting editable as true to let user edit or make changes in edit mode
addressPostcode.setText(Integer.toString(personData.getpostcode()));//setting label text as according to object data
addressPostcode.setEditable(false);//setting editable as true to let user edit or make changes in edit mode
JTextField childrenData[] = new JTextField[personData.getChildrenListSize()]; //creating the array of jtext field with the size of childrenlist size
if(personData.getChildren()!=null)//only perform when there is children data to display
{
childrenLabel = new JLabel ("Children :");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_START;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 16;
leftPanel.add(childrenLabel,c);
children = new JTextField(10);
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_END;
c.weightx = 1;
c.weighty = 0;
c.gridx = 3;
c.gridy = 16;
children.setText(personData.getChildren()); ////setting label text as according to object data
leftPanel.add(children,c);//adding textfield in leftpanel to display on the panel
leftPanel.add( new JLabel(""));//adding label in leftpanel to display on the panel
}
if (personData.getChildrenListSize()!=0)
{
childrenLabel = new JLabel ("Children :");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_END;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 16;
leftPanel.add(childrenLabel,c);
for (int i = 0; i <personData.getChildrenListSize(); i++) //for loop to read until the end of children data
{
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_END;
c.weightx = 1;
c.weighty = 0;
c.gridx = 3;
c.gridy = 16+i;
childrenData[i] = new JTextField(); //creating jtextfield according to the amount of children arrry size
childrenData[i].setText(personData.getChildrens(i).toString()); //setting label text as according to object data
childrenData[i].setEditable(false);//setting editable as false to not let user edit or make changes in view mode
leftPanel.add(childrenData[i],c);//adding textfield in leftpanel to display on the panel
leftPanel.add(new JLabel(""));//adding label in leftpanel to display on the panel
}
}
JTextField grandchildrenData[] = new JTextField[personData.getChildrenListSize()]; //creating array of JTextField with the size of children
if (personData.getgrandChildrenListSize()!=0) //proceed when there is data
{
childrenLabel = new JLabel ("Grand Children :");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_END;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 17 + personData.getChildrenListSize();
leftPanel.add(childrenLabel,c);
leftPanel.add(new JLabel(""));
for (int ii = 0; ii<personData.getgrandChildrenListSize();ii++)
{
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_END;
c.weightx = 1;
c.weighty = 0;
c.gridx = 3;
c.gridy = 17+personData.getChildrenListSize()+ii;
grandchildrenData[ii] = new JTextField(); //creating jtextfield according to the amount of children arrry size
grandchildrenData[ii].setText(personData.getgrandChildren(ii).toString()); //setting label text as according to object data
grandchildrenData[ii].setEditable(false);//setting editable as false to not let user edit or make changes in view mode
leftPanel.add(new JLabel(""));
leftPanel.add(grandchildrenData[ii],c);//adding textfield in leftpanel to display on the panel
leftPanel.add(new JLabel(""));//adding label in leftpanel to display on the panel
leftPanel.revalidate();
leftPanel.repaint();
}
}
JButton editbutton = new JButton ("Edit Details ");//implementing edit button
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_END;
c.weightx = 1;
c.weighty = 0;
c.gridx = 0;
c.gridy = 18+personData.getChildrenListSize()+personData.getgrandChildrenListSize();
leftPanel.add(editbutton,c);
editbutton.addActionListener(new editbuttonObjListener()); //implementing action listener for edit button
JButton AddRealtiveButton = new JButton ("Add Relative");//implementing edit button
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_END;
c.weightx = 0.5;
c.weighty = 0;
c.gridx = 3;
c.gridy = 18+personData.getChildrenListSize()+personData.getgrandChildrenListSize();
leftPanel.add(AddRealtiveButton,c);
AddRealtiveButton.addActionListener(new relativeButtionListener());//implementing action listener for add relative button listener
leftPanel.setVisible(false);// setting leftpanel as false to visible on the panel
leftPanel.setVisible(true);// setting leftpanel as false to visible on the panel
rightPanel.setVisible(false);// setting right panel as true to visible on the panel
rightPanel.setVisible(true);// setting right panel as true to visible on the panel
}
void editGUI(person personData)throws NullPointerException // method which perform as editmode in gui, implementing with exception
{
leftPanel.removeAll(); //removing all the previous data from left panel
leftPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
JLabel editmodetext = new JLabel("Edit Mode"); //creating label to display information
editmodetext.setFont(editmodetext.getFont().deriveFont(Font.BOLD, 17f)); // setting label size and font as bold
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 0;
leftPanel.add(editmodetext,c);// adding label in leftPanel to display on the panel
JLabel personal = new JLabel("Person Information");//implementing new label
personal.setFont(personal.getFont().deriveFont(Font.BOLD, 16f));// setting label size and font as bold
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.weighty = 0.1;
c.gridx = 0;
c.gridy = 1;
leftPanel.add(personal,c);// adding label in leftPanel to display on the panel
firstnameLabel = new JLabel("Name: "); //creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 2;
leftPanel.add(firstnameLabel,c);// adding label in leftPanel to display on the panel
firstname = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 3;
c.gridy = 2;
leftPanel.add(firstname,c);// adding label in leftPanel to display on the panel
firstname.setDocument(new JTextFieldLimit(28));
surnameBirthLabel = new JLabel ("Surname: ");
c.fill = GridBagConstraints.HORIZONTAL; //constraint for gribbaglayout
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 3;
leftPanel.add(surnameBirthLabel,c);//adding label together with constraint
surnameBirth = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 3;
c.gridy = 3;
leftPanel.add(surnameBirth,c);
surnameBirth.setDocument(new JTextFieldLimit(28)); //setting word limit
surnameMarriageLabel = new JLabel ("Maiden Name: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 4;
leftPanel.add(surnameMarriageLabel,c);// adding data with constraint in leftPanel to display on the panel
surnameMarriage = new JTextField(10);//creating new text field for user input
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 3;
c.gridy = 4;
leftPanel.add(surnameMarriage,c);// adding data with constraint in leftPanel to display on the panel
surnameMarriage.setDocument(new JTextFieldLimit(28));
GenderLabel = new JLabel ("Gender: ");//creating new label
c.fill = GridBagConstraints.HORIZONTAL;