-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainInterface.java
More file actions
730 lines (598 loc) · 31.7 KB
/
MainInterface.java
File metadata and controls
730 lines (598 loc) · 31.7 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
//*****************************************************************
// MainInterface.java Author: Ravyar Sarbast
//
// The Main class when app start// it control most aspect of the applications
//*****************************************************************
package RavyarSarbastTahir;
import javax.swing.*;
import javax.swing.border.CompoundBorder;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.NoSuchElementException;
public class MainInterface extends CenteFrame {
private final JPanel mainPanel;
private final MainMenu mainMenuP;
private final LoginPanel loginPanel;
private final BorderLayout borderLayout;
private MenuBar menuBar;
private DefaultTableModel model, modelC;
private JTable westT, details;
private DBConnector dbConnector;
private String selectedTable, selectedCatagory;
// Declaring this instance variable here so I can access them when ever I want
public MainInterface() throws HeadlessException {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {// confirmation for exiting the app
int confirm = JOptionPane.showConfirmDialog(MainInterface.this, "are you sure you want to close");
if (confirm == JOptionPane.YES_OPTION) {
dispose();
}
}
});
mainMenuP = new MainMenu();
loginPanel = new LoginPanel();
loginPanel.getLogin().addActionListener(action());
loginPanel.username.addActionListener(action());
loginPanel.password.addActionListener(action());
Container container = getContentPane();
mainPanel = new JPanel();
container.add(mainPanel);
borderLayout = new BorderLayout();
mainPanel.setLayout(borderLayout);
JPanel bottom = new JPanel();
bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS));
bottom.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(""), BorderFactory.createLineBorder(Color.BLACK, 0)));
JLabel copyrightlabel = new JLabel("All Right Reserved for KUST ");
bottom.add(Box.createHorizontalGlue());
bottom.add(copyrightlabel);
bottom.add(Box.createHorizontalGlue());
container.add(bottom, BorderLayout.SOUTH);
boolean close = false;// here I check for the connection to the data base
try {
dbConnector = new DBConnector();
} catch (ClassNotFoundException e) {
JOptionPane.showMessageDialog(MainInterface.this,"Cant find MariaDB Driver");// if it cant find driver it will show you this message
close= true;
System.exit(0);
}
catch (Exception e){
sqllogin();// if it find the driver but can not connect to the database it will open sql menu so you can enter database login detail
close= true;
}
if(close){
dispose();
}else{
login();}// if database connection succeed it will open login menu
}
public static void main(String[] args) {
MainInterface mainInterface = new MainInterface();
mainInterface.setVisible(true);
mainInterface.setTitle("Chain Management System");
mainInterface.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);// I setup confirm delete I setup close button to do nothing
//this is where I main object of the app
}
void transit() {
cleanscreenn();
tables();
mainPanel.remove(borderLayout.getLayoutComponent(BorderLayout.WEST));
String[] header = {"#", "From", "to", "Departure", "Arrival"};
modelC = new DefaultTableModel(header, 0);
details.setModel(modelC);
super.centerScreen();
dbConnector.readTranset(modelC);
}
void allstatic() {
cleanscreenn();
tables();
mainPanel.remove(borderLayout.getLayoutComponent(BorderLayout.WEST));
String[] header = {"Name", "Count", "Place Name", "Part"};
modelC = new DefaultTableModel(header, 0);
details.setModel(modelC);
super.centerScreen();
dbConnector.stastricsall(modelC);
}
void shippmentP(JButton addData, int part) {// this is shipment page it change the table to shipment, I take the
// button as parameter so I can modify it action listener
String[] header = {"#", "Shipment", "Shipping Date", "Arrival Date"};
modelC = new DefaultTableModel(header, 0);
details.setModel(modelC);
try{addData.removeActionListener(addData.getActionListeners()[0]);// removing older action
}
catch (Exception e){
}
addData.addActionListener(new ActionListener() {//adding new action
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (selectedTable != null) {//adding new shipment
AddShipment addShipment = new AddShipment(0, 0, MainInterface.this);
addShipment.adds.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
SimpleDateFormat formater = new SimpleDateFormat("yyyy/MM/dd");//the date format to show the user
String shipmentformer = formater.format(addShipment.shippmentdate.getValue());
String arrivalfromaeter = formater.format(addShipment.arrivaltime.getValue());
dbConnector.createShipment(addShipment.name.getText(), shipmentformer, arrivalfromaeter, selectedTable, modelC, MainInterface.this, addShipment,part);// create a Shipment
}
});
} else {
JOptionPane.showMessageDialog(MainInterface.this, "Please Select a Place");// this message show if the user try to add data without selecting the place
}
}
});
try{
dbConnector.readShipment(modelC, selectedTable, part);
}
catch (Exception e) {
}
}
void productsP(JButton addData, int part) {
String[] header = {"#", "Name", "Manufacturing Price", "SellingPrice", "Manufacturing Date"};
modelC = new DefaultTableModel(header, 0);
details.setModel(modelC);
addData.removeActionListener(addData.getActionListeners()[0]);
addData.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (selectedTable != null) {
AddProduct addProduct = new AddProduct(0, 0, MainInterface.this);
addProduct.adds.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
SimpleDateFormat formater = new SimpleDateFormat("yyyy/MM/dd");
String manDatefo = formater.format(addProduct.manDate.getValue());
dbConnector.createProduct(addProduct.name.getText(), Double.parseDouble(addProduct.mPrice.getText()), Double.valueOf(addProduct.sPrice.getText()), manDatefo, selectedTable, modelC, MainInterface.this, addProduct,part);
}
});
} else {
JOptionPane.showMessageDialog(MainInterface.this, "Please Select a place");
}
}
});
try{
dbConnector.readProduct(modelC, selectedTable, part);
}catch (Exception e){
}
}
void statstics(int part) {
String[] header = {"Name", "Detail"};
modelC = new DefaultTableModel(header, 0);
details.setModel(modelC);
dbConnector.stastrics(modelC, part);
}
void statsticsS(int part) {
String[] header = {"Name", "Detail"};
modelC = new DefaultTableModel(header, 0);
details.setModel(modelC);
dbConnector.stastricsS(modelC, part);
}
void mainPart(int part) {
selectedCatagory = "em";// when open any part of the app it will come here first location usually is employee
cleanscreenn();// this will remove all JPanels open on main Panel
tables();// this will load west table and center table
JPanel east = new JPanel();// East panel for the bottun
east.setLayout(new BoxLayout(east, BoxLayout.Y_AXIS));// box layout so button will be in order
JPanel eastT = new JPanel();// panel for the button this layout so I can have spacing and order of the button the way I want
eastT.setLayout(new GridLayout(5, 1, 0, 0));
JButton addDataf = new JButton("Add Place");
JButton addData = new JButton("Add Data");
JButton employee = new JButton("Employees");
JButton product = new JButton("Products");
JButton statistic = new JButton("Statistics");
eastT.add(addDataf);
eastT.add(addData);
eastT.add(employee);
eastT.add(product);
eastT.add(statistic);
east.add(eastT);
east.add(Box.createRigidArea(new Dimension(0, 400)));
east.add(Box.createVerticalGlue());
model.setRowCount(0);
String[] header = {"#", "Name", "Job", "Salary"};
modelC = new DefaultTableModel(header, 0);
details.setModel(modelC);
mainPanel.add(east, BorderLayout.EAST);
super.centerScreen();// to resize the app and center it on screen
dbConnector.readPlaces(model, part);// this will load the places from the database and it use part for differ the places its factory or other
details.addMouseListener(new MouseAdapter() {// this will open mouse listener on main table in the center
@Override
public void mouseReleased(MouseEvent e) {
RightClickWestPanel r = new RightClickWestPanel();// this is pop up menu when user click on item on the table in center on screen
r.delete.addActionListener(new ActionListener() {// when user click on delete
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (selectedCatagory.equalsIgnoreCase("em")) {// if user on employee it will delete employee
dbConnector.deleteEmployee(MainInterface.this, details);// delete selected user from
} else if (selectedCatagory.equalsIgnoreCase("pr")) {// this will delete from product
dbConnector.deleteProduct(MainInterface.this, details);
} else {// this one will delete from shipment
dbConnector.deleteShip(MainInterface.this, details);
}
}
});
r.edit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (selectedCatagory.equalsIgnoreCase("em")) {// this will read selected data from employee select it by user
AddEmployee addEmployee = new AddEmployee(0, 0, MainInterface.this);// and it the user change data
int text = Integer.parseInt((String) modelC.getValueAt(details.getSelectedRow(), 0));
String name = (String) modelC.getValueAt(details.getSelectedRow(), 1);
String job = (String) modelC.getValueAt(details.getSelectedRow(), 2);
String salary = String.valueOf(modelC.getValueAt(details.getSelectedRow(), 3));
addEmployee.name.setText(name);
addEmployee.job.setText(job);
addEmployee.salary.setText(salary);
addEmployee.adds.setText("Update");
addEmployee.adds.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
long salaryt = 0l;
int salary = 0;
try {
salaryt = (Long) NumberFormat.getNumberInstance(Locale.UK).parse(addEmployee.salary.getText());
salary = Math.toIntExact(salaryt);
} catch (ParseException e) {
e.printStackTrace();
}
String name = addEmployee.name.getText();
String job = addEmployee.job.getText();
dbConnector.editEmployee(text, name, job, salary, selectedTable, modelC, MainInterface.this, addEmployee, details.getSelectedRow());
}
});
} else if (selectedCatagory.equalsIgnoreCase("pr")) {
AddProduct addProduct = new AddProduct(0, 0, MainInterface.this);
int text = Integer.parseInt((String) modelC.getValueAt(details.getSelectedRow(), 0));
String name = (String) modelC.getValueAt(details.getSelectedRow(), 1);
String manprice = String.valueOf(modelC.getValueAt(details.getSelectedRow(), 2));
String selprice = String.valueOf(modelC.getValueAt(details.getSelectedRow(), 3));
String expire = (String) modelC.getValueAt(details.getSelectedRow(), 4);
Date date1 = null;
try {
date1 = new SimpleDateFormat("yyyy-MM-dd").parse(expire);
} catch (ParseException parseException) {
try{
date1 = new SimpleDateFormat("yyyy/MM/dd").parse(expire);
}
catch (Exception e){
}
}
addProduct.name.setText(name);
addProduct.mPrice.setText(String.valueOf(manprice));
addProduct.sPrice.setText(String.valueOf(selprice));
addProduct.manDate.setValue(date1);
addProduct.adds.setText("Update");
addProduct.adds.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String name = addProduct.name.getText();
double manprice = Double.parseDouble(addProduct.mPrice.getText());
double selprice = Double.parseDouble(addProduct.sPrice.getText());
SimpleDateFormat formater = new SimpleDateFormat("yyyy/MM/dd");
String manDatefo = formater.format(addProduct.manDate.getValue());
dbConnector.editProduct(text, name, manprice, selprice, manDatefo, selectedTable, modelC, MainInterface.this, addProduct, details.getSelectedRow());
}
});
} else {
AddShipment addShipment = new AddShipment(0, 0, MainInterface.this);
int text = Integer.parseInt((String) modelC.getValueAt(details.getSelectedRow(), 0));
String shipment = (String) modelC.getValueAt(details.getSelectedRow(), 1);
String shippingDate = (String) modelC.getValueAt(details.getSelectedRow(), 2);
String arrivalTime = (String) modelC.getValueAt(details.getSelectedRow(), 3);
Date date1 = null;
try {
date1 = new SimpleDateFormat("yyyy-MM-dd").parse(shippingDate);
} catch (ParseException parseException) {
//parseException.printStackTrace();
try{
date1 = new SimpleDateFormat("yyyy/MM/dd").parse(shippingDate);
}
catch (Exception e){
}
}
Date date2 = null;
try {
date2 = new SimpleDateFormat("yyyy-MM-dd").parse(arrivalTime);
} catch (ParseException parseException) {
try{
date2 = new SimpleDateFormat("yyyy/MM/dd").parse(arrivalTime);
}
catch (Exception e){
}
}
addShipment.placeholderName.setText("Shipment");
addShipment.name.setText(shipment);
addShipment.arrivaltime.setValue(date1);
addShipment.shippmentdate.setValue(date2);
addShipment.adds.setText("Update");
addShipment.adds.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String name = addShipment.name.getText();
SimpleDateFormat formater = new SimpleDateFormat("yyyy/MM/dd");
String ship = formater.format(addShipment.shippmentdate.getValue());
String arrive = formater.format(addShipment.arrivaltime.getValue());
dbConnector.editShipment(text, name, ship, arrive, selectedTable, modelC, MainInterface.this, addShipment, details.getSelectedRow());
}
});
}
}
});
if (details.getSelectedRow() > -1 && e.getButton() == MouseEvent.BUTTON3) {
r.show(westT, e.getX(), e.getY());
}
}
});
westT.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
RightClickWestPanel r = new RightClickWestPanel();// this is pop up menu on west table
r.delete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
dbConnector.deletePlaces(MainInterface.this, westT, part);
}
});// this will delete selected item, how ever due mysql constrain it will not delete a place if there is data in it
r.edit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
AddPlace addPlace = new AddPlace(e.getX(), e.getY(), MainInterface.this);
addPlace.adds.setText("Update");
String text = (String) model.getValueAt(westT.getSelectedRow(), westT.getSelectedColumn());
addPlace.factoryName.setText(text);
addPlace.setTitle(text);
addPlace.adds.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
dbConnector.editPlaces(addPlace.factoryName.getText().trim(), text, westT.getSelectedRow(), model, MainInterface.this, addPlace, part);
}
});
}
});//
int selected = westT.getSelectedRow();
selectedTable = (String) model.getValueAt(westT.getSelectedRow(), westT.getSelectedColumn());
if (selectedCatagory.equalsIgnoreCase("em")) {
dbConnector.readEmployee(modelC, selectedTable, part);
} else if (selectedCatagory.equalsIgnoreCase("pr")) {
dbConnector.readProduct(modelC, selectedTable, part);
} else {
dbConnector.readShipment(modelC, selectedTable, part);
}
if (e.getButton() == MouseEvent.BUTTON3 && selected > -1) {
r.show(westT, e.getX(), e.getY());
}
}
});
addDataf.addActionListener(new ActionListener() {// this will open window to insert place
@Override
public void actionPerformed(ActionEvent actionEvent) {
int x = MainInterface.this.getSize().width / 4;
int y = MainInterface.this.getSize().height / 4;
AddPlace addPlace = new AddPlace(x, y, MainInterface.this);
addPlace.adds.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
dbConnector.createPlace(addPlace.factoryName.getText().trim(), model, MainInterface.this, addPlace, part);
}
});
}
});
if (part == 2 || part == 4) {// stores and supplier have shipment instead of employee
selectedCatagory = "sh";// select catagory as shipment
employee.setText("Shipment");
shippmentP(addData, part);// loading shipment table headers
employee.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
shippmentP(addData, part);// to load shipment when user click on the shipment button
}
});
statistic.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
statsticsS(part);
//JOptionPane.showMessageDialog(MainInterface.this,"Coming soon in upcoming versions");
}
});
} else { try{
dbConnector.readEmployee(modelC, selectedTable, part);// read user data used try and catch to avoid if there is no data or nothing selected
}
catch (Exception e){
}
employee.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
mainPart(part);
}
});
statistic.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
statstics(part);
//JOptionPane.showMessageDialog(MainInterface.this,"Coming soon in upcoming versions");
}
});
}
product.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
selectedCatagory = "pr";// to load factory when user click on factory
// dbConnector.readFactoryEmThread(modelC,selectedTable,part);
productsP(addData, part);
}
});
addData.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (selectedTable != null) {
AddEmployee addEmployee = new AddEmployee(0, 0, MainInterface.this);
addEmployee.adds.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {// adding employee but making user place is selected
String name = addEmployee.name.getText();
String job = addEmployee.job.getText();
Long salaryt = 0l;
int salary = 0;
try {
salaryt = (Long) NumberFormat.getNumberInstance(Locale.UK).parse(addEmployee.salary.getText());
salary = Math.toIntExact(salaryt);
} catch (ParseException e) {
e.printStackTrace();
}
dbConnector.createEmployee(name, job, salary, selectedTable, modelC, MainInterface.this, addEmployee,part);
}
});
} else {
JOptionPane.showMessageDialog(MainInterface.this, "Please Select a place");
}
}
});
}
void tables() {// creating tables so I only write this once and use it when I need it
CompoundBorder myBorder = BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(""), BorderFactory.createLineBorder(Color.BLACK, 0));
JPanel west = new JPanel();
String[] columnNames = {"Name"};
model = new DefaultTableModel(columnNames, 0);
westT = new JTable(model);
westT.setTableHeader(null);
westT.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
westT.setDefaultEditor(Object.class, null);
west.setLayout(new BoxLayout(west,BoxLayout.X_AXIS));
west.setPreferredSize(new Dimension(120,west.getHeight()));
JScrollPane scrollPane = new JScrollPane(westT,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
west.add(scrollPane);// adding scroll pane so I have more data user can scroll down the data
mainPanel.add(west, BorderLayout.WEST);
JPanel center = new JPanel();
center.setLayout(new BorderLayout());
details = new JTable();
center.add(details.getTableHeader(), BorderLayout.NORTH);
JScrollPane scrollPane1 = new JScrollPane(details,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
center.setLayout(new BoxLayout(center,BoxLayout.X_AXIS));
center.add(scrollPane1, BorderLayout.CENTER);
mainPanel.add(center, BorderLayout.CENTER);
west.setBorder(myBorder);
center.setBorder(myBorder);
getContentPane().revalidate();
}
void mainMenu() {
cleanscreenn();
mainPanel.add(mainMenuP);
menuBar = new MenuBar();
setJMenuBar(menuBar);
super.pack();
setLocationRelativeTo(null);
ActionListener openF = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
mainPart(1);// this open factories
}
};
ActionListener openM = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
mainMenu();// open Main Menu
}
};
ActionListener openS = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
mainPart(2);// Open Stores
}
};
ActionListener openW = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
mainPart(3);// Open Warehouses
}
};
ActionListener openT = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
transit(); // open transit
}
};
ActionListener openSP = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
mainPart(4); //Open supplier
}
};
ActionListener openSS = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
allstatic(); // open statistics
}
};
menuBar.factories.addActionListener(openF);
mainMenuP.getFactories().addActionListener(openF);
mainMenuP.getStores().addActionListener(openS);
menuBar.stores.addActionListener(openS);
menuBar.mainmenu.addActionListener(openM);
mainMenuP.getWarehouse().addActionListener(openW);
menuBar.warehouse.addActionListener(openW);
mainMenuP.getTransit().addActionListener(openT);
menuBar.transit.addActionListener(openT);
mainMenuP.getSupplier().addActionListener(openSP);
menuBar.supplier.addActionListener(openSP);
mainMenuP.getStatistics().addActionListener(openSS);
menuBar.statistics.addActionListener(openSS);
menuBar.logout.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
login();
}
});
menuBar.aboutme.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
JOptionPane.showMessageDialog(MainInterface.this, "This software written by \n Ravyar Sarbast Tahir");
}
});
}
void cleanscreenn() throws NoSuchElementException {// this method will remove all panel from main panel
try {
mainPanel.remove(borderLayout.getLayoutComponent(BorderLayout.CENTER));
mainPanel.remove(borderLayout.getLayoutComponent(BorderLayout.WEST));
mainPanel.remove(borderLayout.getLayoutComponent(BorderLayout.EAST));
} catch (Exception e) {
}
}
boolean checkpassword(JTextField username, JPasswordField password) {// this method check for user login if it true it will return true to where it invoked from
return dbConnector.login(username.getText().strip(), (String.valueOf(password.getPassword())).strip());
}
void sqllogin(){
SQLScreen sqlScreen = new SQLScreen(MainInterface.this);
setJMenuBar(null);
cleanscreenn();
mainPanel.add(sqlScreen, BorderLayout.CENTER);
super.pack();// this will resize the application to match my elements on screen
setLocationRelativeTo(null);// to stay in the middle
}
ActionListener action(){
ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (checkpassword(loginPanel.username, loginPanel.password)) {
loginPanel.username.setText("");
loginPanel.password.setText("");
mainMenu();// if the password is correct it will open main menu of the app
} else {
JOptionPane.showMessageDialog(MainInterface.this, "Either username or password is wrong"); // let user know either username or password is wrong
}
}
};
return actionListener;
}
void login() {
setJMenuBar(null);
cleanscreenn();
mainPanel.add(loginPanel, BorderLayout.CENTER);
super.pack();
setLocationRelativeTo(null);
}
}