-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProject.java
2902 lines (2436 loc) · 117 KB
/
Project.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.EventQueue;
import javax.swing.JFrame;
import java.awt.CardLayout;
import javax.swing.JPanel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
//PACKAGE DETAILS
import pDealer.Dealer;
import pCustomer.Customer;
import pVehicle.Vehicle;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
public class Project {
private JFrame frmVehicleManagementSystem;
private JTextField AUsernameField;
private JPasswordField APasswordField;
private JTextField DUsernameField;
private JPasswordField DPasswordField;
private JTextField DNUsernameField;
private JPasswordField DNPasswordField;
private JTextField txtDNName;
private JTextField txtDNPhone;
private JTextField txtDNEmail;
private JTable table;
private JTextField modelField;
private JTextField priceField;
private JTextField colorField;
private JTextField CUsernameField;
private JPasswordField CPasswordField;
private JTextField CNUsernameField;
private JPasswordField CNPasswordField;
private JTextField CNNameField;
private JTextField CNPhoneField;
private JTextField CNEmailField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
Project window = new Project();
window.frmVehicleManagementSystem.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Project() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
//Set up page classes
Dealer d=new Dealer();
Vehicle vh=new Vehicle();
Customer cs=new Customer();
//default accounts
d.addDealer("admin","admin","Mario","Palghar","1234567890","[email protected]");
d.loginDealer("admin", "admin", vh);
vh.addVehicle("admin",400, "Volkswagen", "Polo", "Hatchback", "2011", "Red", "Petrol", "14,00,000");
vh.addVehicle("admin",400, "Toyota", "Corolla", "Sedan", "2004", "White", "Petrol", "10,00,000");
cs.addCustomer("admin","admin","Mario","Palghar","1234567890","[email protected]");
cs.loginCustomer("admin", "admin", vh);
vh.buyVehicle(101, "admin", 300);
//MAIN PAGE
frmVehicleManagementSystem = new JFrame();
frmVehicleManagementSystem.setResizable(false);
frmVehicleManagementSystem.setTitle("Vehicle Management System");
frmVehicleManagementSystem.setBounds(100, 100, 700, 430);
frmVehicleManagementSystem.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmVehicleManagementSystem.getContentPane().setLayout(new CardLayout(0, 0));
JPanel mainmenupanel = new JPanel();
frmVehicleManagementSystem.getContentPane().add(mainmenupanel, "name_2605759473900");
mainmenupanel.setLayout(null);
//setting up panels
JPanel adminloginpanel = new JPanel();
JPanel dealerloginpanel = new JPanel();
JPanel dealernewpanel = new JPanel();
JPanel customernewpanel = new JPanel();
JPanel customerloginpanel = new JPanel();
//MAIN MENU SCREEN
JLabel lblVehicleManagementSystem = new JLabel("VEHICLE MANAGEMENT SYSTEM");
lblVehicleManagementSystem.setBackground(Color.PINK);
lblVehicleManagementSystem.setFont(new Font("Tahoma", Font.BOLD, 30));
lblVehicleManagementSystem.setForeground(Color.RED);
lblVehicleManagementSystem.setHorizontalAlignment(SwingConstants.CENTER);
lblVehicleManagementSystem.setBounds(10, 11, 674, 100);
mainmenupanel.add(lblVehicleManagementSystem);
//Main Menu buttons
JButton btnAdmin = new JButton("ADMIN");
btnAdmin.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainmenupanel.setVisible(false);
adminloginpanel.setVisible(true);
}
});
btnAdmin.setBounds(38, 122, 145, 50);
mainmenupanel.add(btnAdmin);
JButton btnDealer = new JButton("DEALER");
btnDealer.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainmenupanel.setVisible(false);
dealerloginpanel.setVisible(true);
}
});
btnDealer.setBounds(193, 122, 145, 50);
mainmenupanel.add(btnDealer);
JButton btnCustomer = new JButton("CUSTOMER");
btnCustomer.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainmenupanel.setVisible(false);
customerloginpanel.setVisible(true);
}
});
btnCustomer.setBounds(348, 122, 145, 50);
mainmenupanel.add(btnCustomer);
JButton btnVehicles = new JButton("VEHICLES");
btnVehicles.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
mainmenupanel.setVisible(false);
//VIEW VEHICLE PANEL
JPanel viewvehiclespanel = new JPanel();
viewvehiclespanel.setLayout(null);
frmVehicleManagementSystem.getContentPane().add(viewvehiclespanel, "name_35127525940900");
JLabel lblVehicleList = new JLabel("Vehicle List");
lblVehicleList.setHorizontalAlignment(SwingConstants.CENTER);
lblVehicleList.setFont(new Font("Tahoma", Font.BOLD, 20));
lblVehicleList.setBounds(262, 11, 160, 50);
viewvehiclespanel.add(lblVehicleList);
JButton button_6 = new JButton("Back");
button_6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
viewvehiclespanel.setVisible(false);
mainmenupanel.setVisible(true);
}
});
button_6.setToolTipText("Go Back");
button_6.setBounds(595, 11, 89, 23);
viewvehiclespanel.add(button_6);
JScrollPane scrollPane_1 = new JScrollPane();
scrollPane_1.setBounds(10, 72, 674, 245);
viewvehiclespanel.add(scrollPane_1);
//TABLE SETUP FIRST TIME
vh.displayAllVehicles();
table = new JTable();
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultEditor(Object.class, null);
String[] columnNames1= {"Dealer ID","Username","Vehicle ID","Brand","Model","Type","Colour","Year","Fuel Type","Price","Status"};
table.setModel(new DefaultTableModel(columnNames1,vh.Vid.size()));
//ADDING ENTRIES IN TABLE
for(int i=0;i<vh.Vid.size();i++) {
table.setValueAt(vh.Did.get(i), i, 0);
table.setValueAt(vh.Dname.get(i), i, 1);
table.setValueAt(vh.Vid.get(i), i, 2);
table.setValueAt(vh.Vbrand.get(i), i, 3);
table.setValueAt(vh.Vmodel.get(i), i, 4);
table.setValueAt(vh.Vtype.get(i), i, 5);
table.setValueAt(vh.Vcolor.get(i), i, 6);
table.setValueAt(vh.Vyear.get(i), i, 7);
table.setValueAt(vh.Vfuel.get(i), i, 8);
table.setValueAt(vh.Vprice.get(i), i, 9);
table.setValueAt(vh.Vstatus.get(i), i, 10);
}
vh.clearall();
scrollPane_1.setViewportView(table);
//TOGGLE BUTTONS
JButton btnDisplayVehicles = new JButton("Display Vehicles");
JButton btnDisplayDealers = new JButton("Display Dealers");
btnDisplayDealers.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//DISPLAY DEALERS WITH INFO
d.displayAllDealers();
table.removeAll();
table = new JTable();
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultEditor(Object.class, null);
String[] columnNames= {"Dealer ID","Username","Name","Region","Phone","Email"};
table.setModel(new DefaultTableModel(columnNames,d.Did.size()));
//ADDING ENTRIES IN TABLE
for(int i=0;i<d.Did.size();i++) {
table.setValueAt(d.Did.get(i), i, 0);
table.setValueAt(d.Duname.get(i), i, 1);
table.setValueAt(d.Dname.get(i), i, 2);
table.setValueAt(d.Dregion.get(i), i, 3);
table.setValueAt(d.Dphone.get(i), i, 4);
table.setValueAt(d.Demail.get(i), i, 5);
}
d.clearall();
scrollPane_1.setViewportView(table);
btnDisplayVehicles.setVisible(true);
btnDisplayDealers.setVisible(false);
}
});
btnDisplayDealers.setBounds(524, 328, 160, 50);
viewvehiclespanel.add(btnDisplayDealers);
btnDisplayVehicles.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//DISPLAY VEHICLES AGAIN
vh.displayAllVehicles();
table.removeAll();
table = new JTable();
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultEditor(Object.class, null);
String[] columnNames1= {"Dealer ID","Username","Vehicle ID","Brand","Model","Type","Colour","Year","Fuel Type","Price","Status"};
table.setModel(new DefaultTableModel(columnNames1,vh.Vid.size()));
//ADDING ENTRIES IN TABLE
for(int i=0;i<vh.Vid.size();i++) {
table.setValueAt(vh.Did.get(i), i, 0);
table.setValueAt(vh.Dname.get(i), i, 1);
table.setValueAt(vh.Vid.get(i), i, 2);
table.setValueAt(vh.Vbrand.get(i), i, 3);
table.setValueAt(vh.Vmodel.get(i), i, 4);
table.setValueAt(vh.Vtype.get(i), i, 5);
table.setValueAt(vh.Vcolor.get(i), i, 6);
table.setValueAt(vh.Vyear.get(i), i, 7);
table.setValueAt(vh.Vfuel.get(i), i, 8);
table.setValueAt(vh.Vprice.get(i), i, 9);
table.setValueAt(vh.Vstatus.get(i), i, 10);
}
vh.clearall();
scrollPane_1.setViewportView(table);
btnDisplayVehicles.setVisible(false);
btnDisplayDealers.setVisible(true);
}
});
btnDisplayVehicles.setBounds(524, 328, 160, 50);
viewvehiclespanel.add(btnDisplayVehicles);
//COMBO BOXES FOR SORTING
JComboBox<String> BrandcomboBox = new JComboBox<String>();
JComboBox<String> TypecomboBox = new JComboBox<String>();
JComboBox<String> FuelcomboBox = new JComboBox<String>();
JComboBox<String> DealercomboBox = new JComboBox<String>();
BrandcomboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//SORTING ADD TO EVERY COMBO BOX
vh.displaySortedVehicles((String) DealercomboBox.getSelectedItem(), (String) BrandcomboBox.getSelectedItem(), (String) TypecomboBox.getSelectedItem(), (String) FuelcomboBox.getSelectedItem());
table.removeAll();
table = new JTable();
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultEditor(Object.class, null);
String[] columnNames1= {"Dealer ID","Username","Vehicle ID","Brand","Model","Type","Colour","Year","Fuel Type","Price","Status"};
table.setModel(new DefaultTableModel(columnNames1,vh.Vid.size()));
//ADDING ENTRIES IN TABLE
for(int i=0;i<vh.Vid.size();i++) {
table.setValueAt(vh.Did.get(i), i, 0);
table.setValueAt(vh.Dname.get(i), i, 1);
table.setValueAt(vh.Vid.get(i), i, 2);
table.setValueAt(vh.Vbrand.get(i), i, 3);
table.setValueAt(vh.Vmodel.get(i), i, 4);
table.setValueAt(vh.Vtype.get(i), i, 5);
table.setValueAt(vh.Vcolor.get(i), i, 6);
table.setValueAt(vh.Vyear.get(i), i, 7);
table.setValueAt(vh.Vfuel.get(i), i, 8);
table.setValueAt(vh.Vprice.get(i), i, 9);
table.setValueAt(vh.Vstatus.get(i), i, 10);
}
vh.clearall();
scrollPane_1.setViewportView(table);
btnDisplayVehicles.setVisible(false);
btnDisplayDealers.setVisible(true);
}
});
BrandcomboBox.setModel(new DefaultComboBoxModel<String>(new String[] {"", "Toyota", "Honda", "Ford", "Volkswagen", "Nissan", "Chevrolet", "Hyundai", "Renault", "Skoda", "Fiat", "Tata", "Jeep", "Ferrari", "Lamborghini", "Bugatti", "BMW", "Maruti", "Tesla"}));
BrandcomboBox.setBounds(78, 358, 100, 20);
viewvehiclespanel.add(BrandcomboBox);
TypecomboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//SORTING ADD TO EVERY COMBO BOX
vh.displaySortedVehicles((String) DealercomboBox.getSelectedItem(), (String) BrandcomboBox.getSelectedItem(), (String) TypecomboBox.getSelectedItem(), (String) FuelcomboBox.getSelectedItem());
table.removeAll();
table = new JTable();
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultEditor(Object.class, null);
String[] columnNames1= {"Dealer ID","Username","Vehicle ID","Brand","Model","Type","Colour","Year","Fuel Type","Price","Status"};
table.setModel(new DefaultTableModel(columnNames1,vh.Vid.size()));
//ADDING ENTRIES IN TABLE
for(int i=0;i<vh.Vid.size();i++) {
table.setValueAt(vh.Did.get(i), i, 0);
table.setValueAt(vh.Dname.get(i), i, 1);
table.setValueAt(vh.Vid.get(i), i, 2);
table.setValueAt(vh.Vbrand.get(i), i, 3);
table.setValueAt(vh.Vmodel.get(i), i, 4);
table.setValueAt(vh.Vtype.get(i), i, 5);
table.setValueAt(vh.Vcolor.get(i), i, 6);
table.setValueAt(vh.Vyear.get(i), i, 7);
table.setValueAt(vh.Vfuel.get(i), i, 8);
table.setValueAt(vh.Vprice.get(i), i, 9);
table.setValueAt(vh.Vstatus.get(i), i, 10);
}
vh.clearall();
scrollPane_1.setViewportView(table);
btnDisplayVehicles.setVisible(false);
btnDisplayDealers.setVisible(true);
}
});
TypecomboBox.setModel(new DefaultComboBoxModel<String>(new String[] {"", "Hatchback", "Sedan", "MPV", "SUV", "Convertible", "Pickup", "Coupe"}));
TypecomboBox.setBounds(244, 328, 100, 20);
viewvehiclespanel.add(TypecomboBox);
FuelcomboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//SORTING ADD TO EVERY COMBO BOX
vh.displaySortedVehicles((String) DealercomboBox.getSelectedItem(), (String) BrandcomboBox.getSelectedItem(), (String) TypecomboBox.getSelectedItem(), (String) FuelcomboBox.getSelectedItem());
table.removeAll();
table = new JTable();
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultEditor(Object.class, null);
String[] columnNames1= {"Dealer ID","Username","Vehicle ID","Brand","Model","Type","Colour","Year","Fuel Type","Price","Status"};
table.setModel(new DefaultTableModel(columnNames1,vh.Vid.size()));
//ADDING ENTRIES IN TABLE
for(int i=0;i<vh.Vid.size();i++) {
table.setValueAt(vh.Did.get(i), i, 0);
table.setValueAt(vh.Dname.get(i), i, 1);
table.setValueAt(vh.Vid.get(i), i, 2);
table.setValueAt(vh.Vbrand.get(i), i, 3);
table.setValueAt(vh.Vmodel.get(i), i, 4);
table.setValueAt(vh.Vtype.get(i), i, 5);
table.setValueAt(vh.Vcolor.get(i), i, 6);
table.setValueAt(vh.Vyear.get(i), i, 7);
table.setValueAt(vh.Vfuel.get(i), i, 8);
table.setValueAt(vh.Vprice.get(i), i, 9);
table.setValueAt(vh.Vstatus.get(i), i, 10);
}
vh.clearall();
scrollPane_1.setViewportView(table);
btnDisplayVehicles.setVisible(false);
btnDisplayDealers.setVisible(true);
}
});
FuelcomboBox.setModel(new DefaultComboBoxModel<String>(new String[] {"", "Petrol", "Diesel", "Petrol/Diesel", "CNG", "Electric"}));
FuelcomboBox.setBounds(244, 358, 100, 20);
viewvehiclespanel.add(FuelcomboBox);
DealercomboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//SORTING ADD TO EVERY COMBO BOX
vh.displaySortedVehicles((String) DealercomboBox.getSelectedItem(), (String) BrandcomboBox.getSelectedItem(), (String) TypecomboBox.getSelectedItem(), (String) FuelcomboBox.getSelectedItem());
table.removeAll();
table = new JTable();
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultEditor(Object.class, null);
String[] columnNames1= {"Dealer ID","Username","Vehicle ID","Brand","Model","Type","Colour","Year","Fuel Type","Price","Status"};
table.setModel(new DefaultTableModel(columnNames1,vh.Vid.size()));
//ADDING ENTRIES IN TABLE
for(int i=0;i<vh.Vid.size();i++) {
table.setValueAt(vh.Did.get(i), i, 0);
table.setValueAt(vh.Dname.get(i), i, 1);
table.setValueAt(vh.Vid.get(i), i, 2);
table.setValueAt(vh.Vbrand.get(i), i, 3);
table.setValueAt(vh.Vmodel.get(i), i, 4);
table.setValueAt(vh.Vtype.get(i), i, 5);
table.setValueAt(vh.Vcolor.get(i), i, 6);
table.setValueAt(vh.Vyear.get(i), i, 7);
table.setValueAt(vh.Vfuel.get(i), i, 8);
table.setValueAt(vh.Vprice.get(i), i, 9);
table.setValueAt(vh.Vstatus.get(i), i, 10);
}
vh.clearall();
scrollPane_1.setViewportView(table);
btnDisplayVehicles.setVisible(false);
btnDisplayDealers.setVisible(true);
}
});
DealercomboBox.setModel(new DefaultComboBoxModel<String>(d.DealerList()));
DealercomboBox.setBounds(78, 327, 100, 20);
viewvehiclespanel.add(DealercomboBox);
JLabel lblDealer = new JLabel("Dealer :");
lblDealer.setHorizontalAlignment(SwingConstants.CENTER);
lblDealer.setBounds(20, 330, 46, 14);
viewvehiclespanel.add(lblDealer);
JLabel lblBrand_1 = new JLabel("Brand :");
lblBrand_1.setHorizontalAlignment(SwingConstants.CENTER);
lblBrand_1.setBounds(22, 361, 46, 14);
viewvehiclespanel.add(lblBrand_1);
JLabel lblNewLabel_6 = new JLabel("Type :");
lblNewLabel_6.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_6.setBounds(188, 331, 46, 14);
viewvehiclespanel.add(lblNewLabel_6);
JLabel lblFuel = new JLabel("Fuel :");
lblFuel.setHorizontalAlignment(SwingConstants.CENTER);
lblFuel.setBounds(188, 362, 46, 14);
viewvehiclespanel.add(lblFuel);
//DISPLAY DEALER INFO BUTTON
JButton btnDealerInfo = new JButton("Dealer Info");
btnDealerInfo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (table.getSelectedRow() != -1) {
d.findDealer((String) table.getValueAt(table.getSelectedRow(), 1));
JPanel dealerinfopanel = new JPanel();
dealerinfopanel.setLayout(null);
frmVehicleManagementSystem.getContentPane().add(dealerinfopanel, "name_66305818664800");
JLabel lblCustomerDetails = new JLabel("Dealer Details");
lblCustomerDetails.setHorizontalAlignment(SwingConstants.CENTER);
lblCustomerDetails.setFont(new Font("Tahoma", Font.BOLD, 20));
lblCustomerDetails.setBounds(234, 11, 223, 50);
dealerinfopanel.add(lblCustomerDetails);
JLabel label_2 = new JLabel("Username :");
label_2.setHorizontalAlignment(SwingConstants.CENTER);
label_2.setBounds(188, 116, 97, 14);
dealerinfopanel.add(label_2);
JButton button = new JButton("Back");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dealerinfopanel.setVisible(false);
viewvehiclespanel.setVisible(true);
}
});
button.setToolTipText("Go Back");
button.setBounds(595, 11, 89, 23);
dealerinfopanel.add(button);
JLabel label_7 = new JLabel("Name :");
label_7.setHorizontalAlignment(SwingConstants.CENTER);
label_7.setBounds(188, 141, 97, 14);
dealerinfopanel.add(label_7);
JLabel label_8 = new JLabel(" Region :");
label_8.setHorizontalAlignment(SwingConstants.CENTER);
label_8.setBounds(188, 166, 97, 14);
dealerinfopanel.add(label_8);
JLabel label_9 = new JLabel("Phone No :");
label_9.setHorizontalAlignment(SwingConstants.CENTER);
label_9.setBounds(188, 191, 97, 14);
dealerinfopanel.add(label_9);
JLabel label_10 = new JLabel("Email :");
label_10.setHorizontalAlignment(SwingConstants.CENTER);
label_10.setBounds(188, 216, 97, 14);
dealerinfopanel.add(label_10);
JLabel label_11 = new JLabel(d.DealerDetails(0));
label_11.setBounds(295, 116, 162, 14);
dealerinfopanel.add(label_11);
JLabel label_12 = new JLabel(d.DealerDetails(1));
label_12.setBounds(295, 141, 162, 14);
dealerinfopanel.add(label_12);
JLabel label_13 = new JLabel(d.DealerDetails(2));
label_13.setBounds(295, 166, 162, 14);
dealerinfopanel.add(label_13);
JLabel label_14 = new JLabel(d.DealerDetails(3));
label_14.setBounds(295, 191, 162, 14);
dealerinfopanel.add(label_14);
JLabel label_15 = new JLabel(d.DealerDetails(4));
label_15.setBounds(295, 216, 162, 14);
dealerinfopanel.add(label_15);
JLabel lblCustomerId = new JLabel("Dealer ID :");
lblCustomerId.setHorizontalAlignment(SwingConstants.CENTER);
lblCustomerId.setBounds(188, 91, 97, 14);
dealerinfopanel.add(lblCustomerId);
JLabel label_17 = new JLabel(d.DealerDetails(5));
label_17.setBounds(295, 91, 162, 14);
dealerinfopanel.add(label_17);
dealerinfopanel.setVisible(true);
viewvehiclespanel.setVisible(false);
}
else {
JOptionPane.showMessageDialog(null, "Select Dealer from Table.", "No Dealer Selected", JOptionPane.INFORMATION_MESSAGE);
}
}
});
btnDealerInfo.setBounds(354, 328, 160, 50);
viewvehiclespanel.add(btnDealerInfo);
BrandcomboBox .setSelectedIndex(0);
TypecomboBox.setSelectedIndex(0);
FuelcomboBox.setSelectedIndex(0);
DealercomboBox.setSelectedIndex(0);
viewvehiclespanel.setVisible(true);
}
});
btnVehicles.setBounds(503, 122, 145, 50);
mainmenupanel.add(btnVehicles);
//ADMIN LOGIN SCREEN
frmVehicleManagementSystem.getContentPane().add(adminloginpanel, "name_2540431319500");
adminloginpanel.setLayout(null);
JLabel lblAdmLogin = new JLabel("Admin Login");
lblAdmLogin.setFont(new Font("Tahoma", Font.BOLD, 20));
lblAdmLogin.setHorizontalAlignment(SwingConstants.CENTER);
lblAdmLogin.setBounds(277, 11, 150, 50);
adminloginpanel.add(lblAdmLogin);
AUsernameField = new JTextField();
AUsernameField.setToolTipText("Enter username");
AUsernameField.setBounds(295, 85, 117, 20);
adminloginpanel.add(AUsernameField);
AUsernameField.setColumns(10);
APasswordField = new JPasswordField();
APasswordField.setToolTipText("Enter password");
APasswordField.setBounds(295, 143, 117, 20);
adminloginpanel.add(APasswordField);
APasswordField.setColumns(10);
JLabel lblAUsername = new JLabel("Username :");
lblAUsername.setHorizontalAlignment(SwingConstants.CENTER);
lblAUsername.setBounds(188, 88, 97, 14);
adminloginpanel.add(lblAUsername);
JLabel lblAPassword = new JLabel("Password :");
lblAPassword.setHorizontalAlignment(SwingConstants.CENTER);
lblAPassword.setBounds(188, 146, 97, 14);
adminloginpanel.add(lblAPassword);
JButton btnAdminLogin = new JButton("Login");
btnAdminLogin.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String uname=AUsernameField.getText();
String pass= new String(APasswordField.getPassword());
if(uname.equals("admin") && pass.equals("admin")) {
JOptionPane.showMessageDialog(null, "Successfully Logged in.", "Success", JOptionPane.INFORMATION_MESSAGE);
adminloginpanel.setVisible(false);
//SHIFT HERE ADMIN CONTROL PANEL
//ADMIN CONTROL PANEL
JPanel controlpanel = new JPanel();
controlpanel.setLayout(null);
frmVehicleManagementSystem.getContentPane().add(controlpanel, "name_5499278845900");
JLabel lblAdminControlPanel = new JLabel("Admin Control Panel");
lblAdminControlPanel.setHorizontalAlignment(SwingConstants.CENTER);
lblAdminControlPanel.setFont(new Font("Tahoma", Font.BOLD, 20));
lblAdminControlPanel.setBounds(188, 11, 320, 50);
controlpanel.add(lblAdminControlPanel);
JButton btnLogout = new JButton("Logout");
btnLogout.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
controlpanel.setVisible(false);
controlpanel.removeAll();
adminloginpanel.setVisible(true);
}
});
btnLogout.setToolTipText("Go Back");
btnLogout.setBounds(595, 11, 89, 23);
controlpanel.add(btnLogout);
JPanel displaypanel = new JPanel();
displaypanel.setBounds(10, 72, 674, 318);
controlpanel.add(displaypanel);
displaypanel.setLayout(null);
displaypanel.setVisible(false);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(10, 11, 654, 250);
displaypanel.add(scrollPane);
//INITIALIZE BUTTONS
table = new JTable();
JButton Dealerbtn = new JButton("DELETE DEALER");
Dealerbtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(table.getSelectedRow() != -1) {
//DELETE DEALER ACCOUNT
int option= JOptionPane.showConfirmDialog(null, "Are you sure?", "Delete Dealer", JOptionPane.YES_NO_OPTION);
if(option==JOptionPane.YES_OPTION) {
d.deleteDealer((String) table.getValueAt(table.getSelectedRow(), 1), vh);
d.displayAllDealers();
table.removeAll();
table = new JTable();
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultEditor(Object.class, null);
String[] columnNames= {"Dealer ID","Username","Name","Region","Phone","Email"};
table.setModel(new DefaultTableModel(columnNames,d.Did.size()));
//ADDING ENTRIES IN TABLE
for(int i=0;i<d.Did.size();i++) {
table.setValueAt(d.Did.get(i), i, 0);
table.setValueAt(d.Duname.get(i), i, 1);
table.setValueAt(d.Dname.get(i), i, 2);
table.setValueAt(d.Dregion.get(i), i, 3);
table.setValueAt(d.Dphone.get(i), i, 4);
table.setValueAt(d.Demail.get(i), i, 5);
}
d.clearall();
scrollPane.setViewportView(table);
JOptionPane.showMessageDialog(null, "Dealer Deleted", "Delete Dealer", JOptionPane.INFORMATION_MESSAGE);
}
}
else {
JOptionPane.showMessageDialog(null, "No Dealer Selected", "Delete Dealer", JOptionPane.INFORMATION_MESSAGE);
}
}
});
Dealerbtn.setBounds(260, 272, 149, 35);
displaypanel.add(Dealerbtn);
JButton Customerbtn = new JButton("DELETE CUSTOMER");
Customerbtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(table.getSelectedRow() != -1) {
//DELETE DEALER ACCOUNT
int option= JOptionPane.showConfirmDialog(null, "Are you sure?", "Delete Customer", JOptionPane.YES_NO_OPTION);
if(option==JOptionPane.YES_OPTION) {
cs.deleteCustomer((String) table.getValueAt(table.getSelectedRow(), 1), vh);
cs.displayAllCustomers();
table.removeAll();
table = new JTable();
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultEditor(Object.class, null);
String[] columnNames= {"Customer ID","Username","Name","Region","Phone","Email"};
table.setModel(new DefaultTableModel(columnNames,d.Did.size()));
//ADDING ENTRIES IN TABLE
for(int i=0;i<cs.Cid.size();i++) {
table.setValueAt(cs.Cid.get(i), i, 0);
table.setValueAt(cs.Cuname.get(i), i, 1);
table.setValueAt(cs.Cname.get(i), i, 2);
table.setValueAt(cs.Cregion.get(i), i, 3);
table.setValueAt(cs.Cphone.get(i), i, 4);
table.setValueAt(cs.Cemail.get(i), i, 5);
}
cs.clearall();
scrollPane.setViewportView(table);
JOptionPane.showMessageDialog(null, "Customer Deleted", "Delete Customer", JOptionPane.INFORMATION_MESSAGE);
}
}
else {
JOptionPane.showMessageDialog(null, "No Customer Selected", "Delete Customer", JOptionPane.INFORMATION_MESSAGE);
}
}
});
Customerbtn.setBounds(260, 272, 149, 35);
displaypanel.add(Customerbtn);
JButton Vehiclebtn = new JButton("DELETE VEHICLE");
Vehiclebtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (table.getSelectedRow() != -1) {
if(JOptionPane.showConfirmDialog(null, "Delete selected vehicle?", "Delete Vehicle", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION) {
vh.removeVehicle((String)table.getValueAt(table.getSelectedRow(), 0));
vh.displayAllVehicles();
table.removeAll();
table = new JTable();
table.setDefaultEditor(Object.class, null);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
String[] columnNames= {"ID","Brand","Model","Type","Colour","Year","Fuel Type","Price(Rs.)","Status"};
table.setModel(new DefaultTableModel(columnNames,vh.Vid.size()));
//ADDING ENTRIES IN TABLE
for(int i=0;i<vh.Vid.size();i++) {
table.setValueAt(vh.Vid.get(i), i, 0);
table.setValueAt(vh.Vbrand.get(i), i, 1);
table.setValueAt(vh.Vmodel.get(i), i, 2);
table.setValueAt(vh.Vtype.get(i), i, 3);
table.setValueAt(vh.Vcolor.get(i), i, 4);
table.setValueAt(vh.Vyear.get(i), i, 5);
table.setValueAt(vh.Vfuel.get(i), i, 6);
table.setValueAt(vh.Vprice.get(i), i, 7);
table.setValueAt(vh.Vstatus.get(i), i, 8);
}
vh.clearall();
scrollPane.setViewportView(table);
JOptionPane.showMessageDialog(null, "Vehicle deleted.", "Vehicle Deleted", JOptionPane.INFORMATION_MESSAGE);
}
}
else {
JOptionPane.showMessageDialog(null, "Select Vehicle from Table", "No Vehicle Selected", JOptionPane.INFORMATION_MESSAGE);
}
}
});
Vehiclebtn.setBounds(260, 272, 149, 35);
displaypanel.add(Vehiclebtn);
Dealerbtn.setVisible(false);
Customerbtn.setVisible(false);
Vehiclebtn.setVisible(false);
JComboBox<String> comboBox = new JComboBox<String>();
comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
if(comboBox.getSelectedItem().equals("Dealer")) {
//DISPLAY DEALERS WITH INFO
table.removeAll();
d.displayAllDealers();
table = new JTable();
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultEditor(Object.class, null);
String[] columnNames= {"Dealer ID","Username","Name","Region","Phone","Email"};
table.setModel(new DefaultTableModel(columnNames,d.Did.size()));
//ADDING ENTRIES IN TABLE
for(int i=0;i<d.Did.size();i++) {
table.setValueAt(d.Did.get(i), i, 0);
table.setValueAt(d.Duname.get(i), i, 1);
table.setValueAt(d.Dname.get(i), i, 2);
table.setValueAt(d.Dregion.get(i), i, 3);
table.setValueAt(d.Dphone.get(i), i, 4);
table.setValueAt(d.Demail.get(i), i, 5);
}
d.clearall();
scrollPane.setViewportView(table);
Dealerbtn.setVisible(true);
Customerbtn.setVisible(false);
Vehiclebtn.setVisible(false);
displaypanel.setVisible(true);
}
else if (comboBox.getSelectedItem().equals("Customer")) {
//DISPLAY CUSTOMERS WITH INFO
table.removeAll();
cs.displayAllCustomers();
table = new JTable();
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultEditor(Object.class, null);
String[] columnNames= {"Customer ID","Username","Name","Region","Phone","Email"};
table.setModel(new DefaultTableModel(columnNames,cs.Cid.size()));
//ADDING ENTRIES IN TABLE
for(int i=0;i<cs.Cid.size();i++) {
table.setValueAt(cs.Cid.get(i), i, 0);
table.setValueAt(cs.Cuname.get(i), i, 1);
table.setValueAt(cs.Cname.get(i), i, 2);
table.setValueAt(cs.Cregion.get(i), i, 3);
table.setValueAt(cs.Cphone.get(i), i, 4);
table.setValueAt(cs.Cemail.get(i), i, 5);
}
cs.clearall();
scrollPane.setViewportView(table);
Dealerbtn.setVisible(false);
Customerbtn.setVisible(true);
Vehiclebtn.setVisible(false);
displaypanel.setVisible(true);
}
else if (comboBox.getSelectedItem().equals("Vehicle")) {
//DISPLAY VEHICLES WITH INFO
table.removeAll();
//TABLE SETUP FIRST TIME
vh.displayAllVehicles();
table = new JTable();
table.setDefaultEditor(Object.class, null);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
String[] columnNames= {"ID","Brand","Model","Type","Colour","Year","Fuel Type","Price(Rs.)","Status"};
table.setModel(new DefaultTableModel(columnNames,vh.Vid.size()));
//ADDING ENTRIES IN TABLE
for(int i=0;i<vh.Vid.size();i++) {
table.setValueAt(vh.Vid.get(i), i, 0);
table.setValueAt(vh.Vbrand.get(i), i, 1);
table.setValueAt(vh.Vmodel.get(i), i, 2);
table.setValueAt(vh.Vtype.get(i), i, 3);
table.setValueAt(vh.Vcolor.get(i), i, 4);
table.setValueAt(vh.Vyear.get(i), i, 5);
table.setValueAt(vh.Vfuel.get(i), i, 6);
table.setValueAt(vh.Vprice.get(i), i, 7);
table.setValueAt(vh.Vstatus.get(i), i, 8);
}
vh.clearall();
scrollPane.setViewportView(table);
Dealerbtn.setVisible(false);
Customerbtn.setVisible(false);
Vehiclebtn.setVisible(true);
//DELETE VEHICLE BUTTON
displaypanel.setVisible(true);
}
else {
displaypanel.setVisible(false);
}
}
});
comboBox.setModel(new DefaultComboBoxModel<String>(new String[] {"", "Dealer", "Customer", "Vehicle"}));
comboBox.setBounds(10, 42, 100, 20);
controlpanel.add(comboBox);
JLabel lblDisplay = new JLabel("DISPLAY");
lblDisplay.setFont(new Font("Tahoma", Font.BOLD, 16));
lblDisplay.setHorizontalAlignment(SwingConstants.CENTER);
lblDisplay.setBounds(10, 15, 100, 29);
controlpanel.add(lblDisplay);
controlpanel.setVisible(true);
}
else {
JOptionPane.showMessageDialog(null, "Wrong Username/Password.", "Failure", JOptionPane.INFORMATION_MESSAGE);
}
AUsernameField.setText("");
APasswordField.setText("");
}
});
btnAdminLogin.setBounds(295, 190, 117, 40);
adminloginpanel.add(btnAdminLogin);
JButton btnABack = new JButton("Back");
btnABack.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adminloginpanel.setVisible(false);
mainmenupanel.setVisible(true);
}
});
btnABack.setToolTipText("Go Back");
btnABack.setBounds(595, 11, 89, 23);
adminloginpanel.add(btnABack);
//DEALER MAIN MENU
JPanel dealermenupanel = new JPanel();
//DEALER LOGIN SCREEN
dealerloginpanel.setLayout(null);
frmVehicleManagementSystem.getContentPane().add(dealerloginpanel, "name_5094147174700");
JLabel lblDealerLogin = new JLabel("Dealer Login");
lblDealerLogin.setHorizontalAlignment(SwingConstants.CENTER);
lblDealerLogin.setFont(new Font("Tahoma", Font.BOLD, 20));
lblDealerLogin.setBounds(262, 11, 150, 50);
dealerloginpanel.add(lblDealerLogin);
DUsernameField = new JTextField();
DUsernameField.setToolTipText("Enter username");
DUsernameField.setColumns(10);
DUsernameField.setBounds(295, 85, 117, 20);
dealerloginpanel.add(DUsernameField);
DPasswordField = new JPasswordField();
DPasswordField.setToolTipText("Enter password");
DPasswordField.setColumns(10);
DPasswordField.setBounds(295, 143, 117, 20);
dealerloginpanel.add(DPasswordField);
JLabel lblDUsername = new JLabel("Username :");
lblDUsername.setHorizontalAlignment(SwingConstants.CENTER);
lblDUsername.setBounds(188, 88, 97, 14);
dealerloginpanel.add(lblDUsername);
JLabel lblDPassword = new JLabel("Password :");
lblDPassword.setHorizontalAlignment(SwingConstants.CENTER);
lblDPassword.setBounds(188, 146, 97, 14);
dealerloginpanel.add(lblDPassword);
JButton btnDLogin = new JButton("Login");
btnDLogin.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String uname=DUsernameField.getText();
String pass= new String(DPasswordField.getPassword());
if(d.loginDealer(uname,pass,vh)) {
JOptionPane.showMessageDialog(null, "Successfully Logged in.", "Success", JOptionPane.INFORMATION_MESSAGE);
dealerloginpanel.setVisible(false);
//---SHIFT IT HERE--- 411
//DEALER MENU PANEL ---SHIFT THIS LATER
JPanel dealeraccountpanel = new JPanel();