-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainGUI.java
844 lines (801 loc) · 48.7 KB
/
MainGUI.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
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.plaf.FontUIResource;
import javax.swing.text.StyleContext;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;
public class MainGUI extends JFrame {
private JPanel panel1;
private JButton createSubscriptionButton;
private JButton createSubscriberButton;
private JButton searchSubscriberButton;
private JButton listAllSendingOrdersButton;
private JButton createJournalButton;
private JButton searchJournalButton;
private JPanel panel2;
private JButton listSendingOrdersButton;
private JButton saveStateButton;
private JButton loadStateButton;
private JButton listSubscriptionsButton;
private JButton reportStateButton;
private JButton listIncompletePaymentsButton;
private JButton AcceptPaymentButton;
private JButton addSubscriptionButton;
private Distributor distributor;
public MainGUI(Distributor distributor) {
this.distributor = distributor;
setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setIconImage(new ImageIcon("adsiz2.png").getImage());
this.setSize(700, 520);
this.setLocation(550, 220);
setTitle("Socrates Distribution System");
setContentPane(panel1);
setVisible(true);
this.pack();
createJournalButton.addActionListener(new ActionListener() {
String name, ISSN;
int frequency;
double issuePrice;
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
frame.setTitle("Create");
frame.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame.getContentPane().setBackground(new Color(118, 217, 213));
frame.setLayout(new GridLayout(5, 1, 20, 10));
frame.setSize(300, 250);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
TextField textField = new TextField();
TextField textField1 = new TextField();
TextField textField2 = new TextField();
TextField textField3 = new TextField();
textField.setText("Enter name");
textField1.setText("Enter ISSN");
textField2.setText("Enter frequency");
textField3.setText("Enter issuePrice");
//textField.setBounds(100, 100, 100, 50);
JButton button = new JButton("Apply");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
name = textField.getText();
ISSN = textField1.getText();
frequency = Integer.parseInt(textField2.getText());
issuePrice = Double.parseDouble(textField3.getText());
Journal journal = new Journal(name, ISSN, frequency, issuePrice);
if (distributor.addJournal(journal)) {
JOptionPane.showMessageDialog(null, "Journal is successfully created and added to the list!", "Success", JOptionPane.INFORMATION_MESSAGE);
frame.dispose();
return;
} else {
JOptionPane.showMessageDialog(null, "An error is occurred!", "Error", JOptionPane.ERROR_MESSAGE);
frame.dispose();
return;
}
}
});
frame.add(textField);
frame.add(textField1);
frame.add(textField2);
frame.add(textField3);
frame.add(button);
}
});
searchJournalButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
frame.setTitle("Search");
frame.getContentPane().setBackground(new Color(118, 217, 213));
frame.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame.setLayout(new GridLayout(2, 1, 40, 10));
frame.setSize(250, 125);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
TextField textField = new TextField();
textField.setText("Enter ISSN");
JButton button = new JButton();
button.setText("Search Journal");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String ISSN = textField.getText();
Journal journal = distributor.searchJournal(ISSN);
if (journal != null) {
JOptionPane.showMessageDialog(null, "Journal #" + ISSN + "\n" + journal.toString(), "Success", JOptionPane.INFORMATION_MESSAGE);
frame.dispose();
return;
} else {
JOptionPane.showMessageDialog(null, "Journal #" + ISSN + " could not found!", "Error", JOptionPane.ERROR_MESSAGE);
frame.dispose();
return;
}
}
});
frame.add(textField);
frame.add(button);
}
});
createSubscriberButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame1 = new JFrame();
frame1.setTitle("Create");
frame1.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame1.getContentPane().setBackground(new Color(118, 217, 213));
frame1.setLayout(new GridLayout(2, 1, 40, 10));
frame1.setSize(250, 125);
frame1.setVisible(true);
frame1.setLocationRelativeTo(null);
JButton button = new JButton("Individual");
JButton button1 = new JButton("Corporation");
frame1.add(button);
frame1.add(button1);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame1.dispose();
JFrame frame = new JFrame();
frame.setTitle("Create Individual");
frame.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame.getContentPane().setBackground(new Color(118, 217, 213));
frame.setLayout(new GridLayout(7, 1, 40, 10));
frame.setSize(400, 300);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
TextField textField = new TextField("Enter name");
TextField textField1 = new TextField("Enter address");
TextField textField2 = new TextField("Enter credit card number");
TextField textField3 = new TextField("Enter expire month");
TextField textField4 = new TextField("Enter expire year");
TextField textField5 = new TextField("Enter CCV");
frame.add(textField);
frame.add(textField1);
frame.add(textField2);
frame.add(textField3);
frame.add(textField4);
frame.add(textField5);
JButton button2 = new JButton("Apply");
frame.add(button2);
button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Individual individual = new Individual(textField.getText(), textField1.getText(), textField2.getText(), Integer.parseInt(textField3.getText()), Integer.parseInt(textField4.getText()), Integer.parseInt(textField5.getText()));
if (distributor.addSubscriber(individual)) {
String message = "An individual subscriber is successfully created and added to list!";
message += individual.getBillingInformation();
JOptionPane.showMessageDialog(null, message, "Success!", JOptionPane.INFORMATION_MESSAGE);
frame.dispose();
return;
} else {
JOptionPane.showMessageDialog(null, "An error occurred!", "Error", JOptionPane.ERROR_MESSAGE);
frame.dispose();
return;
}
}
});
}
});
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame1.dispose();
JFrame frame = new JFrame();
frame.setTitle("Create Corporation");
frame.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame.getContentPane().setBackground(new Color(118, 217, 213));
frame.setLayout(new GridLayout(9, 1, 40, 10));
frame.setSize(400, 300);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
TextField textField = new TextField("Enter name");
TextField textField1 = new TextField("Enter address");
TextField textField2 = new TextField("Enter bank code");
TextField textField3 = new TextField("Enter bank name");
TextField textField4 = new TextField("Enter issue day");
TextField textField5 = new TextField("Enter issue month");
TextField textField6 = new TextField("Enter issue year");
TextField textField7 = new TextField("Enter account number");
JButton button3 = new JButton("Create Corporation");
frame.add(textField);
frame.add(textField1);
frame.add(textField2);
frame.add(textField3);
frame.add(textField4);
frame.add(textField5);
frame.add(textField6);
frame.add(textField7);
frame.add(button3);
button3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Corporation corporation = new Corporation(textField.getText(), textField1.getText(), Integer.parseInt(textField2.getText()), textField3.getText(), Integer.parseInt(textField4.getText()), Integer.parseInt(textField5.getText()), Integer.parseInt(textField6.getText()), Integer.parseInt(textField7.getText()));
if (distributor.addSubscriber(corporation)) {
String message = "An corporation subscriber is successfully created and added to list!";
message += corporation.getBillingInformation();
JOptionPane.showMessageDialog(null, message, "Success!", JOptionPane.INFORMATION_MESSAGE);
frame.dispose();
return;
} else {
JOptionPane.showMessageDialog(null, "An error occurred!", "Error", JOptionPane.ERROR_MESSAGE);
frame.dispose();
return;
}
}
});
}
});
}
});
searchSubscriberButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
frame.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame.setTitle("Search");
frame.getContentPane().setBackground(new Color(118, 217, 213));
frame.setLayout(new GridLayout(2, 1, 40, 10));
frame.setSize(250, 125);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
TextField textField = new TextField("Enter name");
frame.add(textField);
JButton button = new JButton("Search Subscriber");
frame.add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Subscriber subscriber = distributor.searchSubscriber(textField.getText());
if (subscriber != null) {
JOptionPane.showMessageDialog(null, subscriber.getBillingInformation(), "Subscriber Information", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "Subscriber is not found!", "Error", JOptionPane.ERROR_MESSAGE);
}
frame.dispose();
return;
}
});
}
});
// önce subscription oluştur
// daha sonra onu listeye ekle
createSubscriptionButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
frame.setTitle("Date & Payment Information");
frame.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame.getContentPane().setBackground(new Color(118, 217, 213));
frame.setLayout(new GridLayout(7, 1, 40, 10));
JLabel label = new JLabel("\tDate Information");
frame.setSize(350, 300);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.add(label);
TextField textField = new TextField("Enter start month");
TextField textField2 = new TextField("Enter start year");
frame.add(textField);
frame.add(textField2);
JLabel label1 = new JLabel("\tPayment Information");
frame.add(label1);
TextField textField3 = new TextField("Enter discount ratio");
TextField textField4 = new TextField("Enter received payment");
frame.add(textField3);
frame.add(textField4);
JButton button = new JButton("Confirm");
frame.add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DateInfo dateInfo = new DateInfo(Integer.parseInt(textField.getText()), Integer.parseInt(textField2.getText()));
PaymentInfo paymentInfo = new PaymentInfo(Double.parseDouble(textField3.getText()), Double.parseDouble(textField4.getText()));
frame.dispose();
JFrame frame1 = new JFrame();
frame1.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame1.getContentPane().setBackground(new Color(118, 217, 213));
frame1.setLayout(new GridLayout(4, 1, 40, 10));
frame1.setSize(200, 200);
frame1.setVisible(true);
frame1.setLocationRelativeTo(null);
frame1.setTitle("Create Subscription");
TextField textField5 = new TextField("Enter copies");
TextField textField6 = new TextField("Enter name of the subscriber");
TextField textField7 = new TextField("Enter ISSN of the journal");
frame1.add(textField5);
frame1.add(textField6);
frame1.add(textField7);
JButton button1 = new JButton("Create Subscription");
frame1.add(button1);
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame1.dispose();
String name = textField6.getText();
String ISSN = textField7.getText();
Subscriber subscriber = distributor.searchSubscriber(name);
if (subscriber == null) {
JOptionPane.showMessageDialog(null, name + " named subscriber is not found!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
Journal journal = distributor.searchJournal(ISSN);
if (journal == null) {
JOptionPane.showMessageDialog(null, "Journal #" + ISSN + " is not found!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
Subscription subscription = new Subscription(dateInfo, paymentInfo, Integer.parseInt(textField5.getText()), subscriber, journal);
if (distributor.addSubscription(ISSN, subscriber, subscription)) {
JOptionPane.showMessageDialog(null, "A new subscription is successfully created and added to the list!\n" + subscription.toString(), "Create Subscription", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "An error occurred when adding new subscription!", "Error", JOptionPane.ERROR_MESSAGE);
}
return;
}
});
}
});
}
});
listAllSendingOrdersButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
frame.setTitle("Select Month & Year");
frame.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame.getContentPane().setBackground(new Color(118, 217, 213));
frame.setLayout(new GridLayout(4, 1, 30, 20));
frame.setSize(200, 200);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
JLabel label = new JLabel("Select month & year");
frame.add(label);
TextField textField = new TextField("Enter month");
TextField textField1 = new TextField("Enter year");
frame.add(textField);
frame.add(textField1);
JButton button = new JButton("Confirm");
frame.add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.dispose();
String string = distributor.listAllSendingOrders(Integer.parseInt(textField.getText()), Integer.parseInt(textField1.getText()));
JOptionPane.showMessageDialog(null, " Order List\n" + string, "List of All Sending Orders", JOptionPane.INFORMATION_MESSAGE);
return;
}
});
}
});
listSubscriptionsButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
frame.setTitle("Select Search Type");
frame.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame.getContentPane().setBackground(new Color(118, 217, 213));
frame.setLayout(new GridLayout(2, 1, 30, 20));
frame.setSize(300, 150);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
JButton button = new JButton("List for Subscriber Name");
JButton button1 = new JButton("List for Journal ISSN");
frame.add(button);
frame.add(button1);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
frame.setTitle("Enter Name");
frame.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame.getContentPane().setBackground(new Color(118, 217, 213));
frame.setLayout(new GridLayout(2, 1, 10, 10));
frame.setSize(300, 100);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
TextField textField = new TextField("Enter subscriber name");
frame.add(textField);
JButton jButton = new JButton("Search");
frame.add(jButton);
jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = textField.getText();
JOptionPane.showMessageDialog(null, distributor.listSubscriptions(name), "Subscription List", JOptionPane.INFORMATION_MESSAGE);
frame.dispose();
return;
}
});
}
});
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
frame.setTitle("Enter Journal ISSN");
frame.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame.getContentPane().setBackground(new Color(118, 217, 213));
frame.setLayout(new GridLayout(2, 1, 10, 10));
frame.setSize(300, 100);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
TextField textField = new TextField("Enter journal ISSN");
frame.add(textField);
JButton jButton = new JButton("Search");
frame.add(jButton);
jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String ISSN = textField.getText();
JOptionPane.showMessageDialog(null, distributor.listSubscriptionsForJournal(ISSN), "Subscription List", JOptionPane.INFORMATION_MESSAGE);
frame.dispose();
return;
}
});
}
});
}
});
listSendingOrdersButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
frame.setTitle("List Journal Orders");
frame.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame.getContentPane().setBackground(new Color(118, 217, 213));
frame.setLayout(new GridLayout(4, 1, 30, 18));
frame.setSize(250, 250);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
TextField textField = new TextField("Enter journal ISSN");
TextField textField1 = new TextField("Enter month");
TextField textField2 = new TextField("Enter year");
frame.add(textField);
frame.add(textField1);
frame.add(textField2);
JButton button = new JButton("List");
frame.add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (distributor.searchJournal(textField.getText()) == null) {
JOptionPane.showMessageDialog(null, "Journal #" + textField.getText() + " cannot be found in the list!", "Error", JOptionPane.ERROR_MESSAGE);
} else {
String message = distributor.listSendingOrders(textField.getText(), Integer.parseInt(textField1.getText()), Integer.parseInt(textField2.getText()));
JOptionPane.showMessageDialog(null, message, "List Of Journal #" + textField.getText(), JOptionPane.INFORMATION_MESSAGE);
}
frame.dispose();
return;
}
});
}
});
loadStateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
frame.setTitle("Load State From File");
frame.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame.getContentPane().setBackground(new Color(118, 217, 213));
frame.setLayout(new GridLayout(2, 1, 30, 15));
frame.setSize(300, 120);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
TextField textField = new TextField("Enter filename");
frame.add(textField);
JButton button = new JButton("Load");
frame.add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String message = distributor.loadState(textField.getText());
JOptionPane.showMessageDialog(null, message, "Load State", JOptionPane.INFORMATION_MESSAGE);
frame.dispose();
}
});
}
});
saveStateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
frame.setTitle("Save State To File");
frame.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame.getContentPane().setBackground(new Color(118, 217, 213));
frame.setLayout(new GridLayout(2, 1, 30, 15));
frame.setSize(300, 120);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
TextField textField = new TextField("Enter filename");
frame.add(textField);
JButton button = new JButton("Save");
frame.add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (distributor.saveState(textField.getText())) {
JOptionPane.showMessageDialog(null, "Current state is successfully saved to " + textField.getText() + "!", "Success", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "Current state cannot be saved!", "Error", JOptionPane.ERROR_MESSAGE);
}
frame.dispose();
return;
}
});
}
});
listIncompletePaymentsButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!distributor.listIncompletePayments().isEmpty()) {
String message = " List Of Incomplete Payments\n *************************************\n";
message += distributor.listIncompletePayments();
JOptionPane.showMessageDialog(null, message, "List Of Incomplete Payments", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "There is zero instance of incomplete payments!", "List Of Incomplete Payments", JOptionPane.INFORMATION_MESSAGE);
}
return;
}
});
reportStateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame1 = new JFrame();
frame1.setTitle("Select Month & Year");
frame1.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame1.getContentPane().setBackground(new Color(118, 217, 213));
frame1.setLayout(new GridLayout(3, 1, 30, 15));
frame1.setSize(300, 150);
frame1.setVisible(true);
frame1.setLocationRelativeTo(null);
TextField textField = new TextField("Enter month");
TextField textField1 = new TextField("Enter year");
frame1.add(textField);
frame1.add(textField1);
JButton button = new JButton("Confirm");
frame1.add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame1.dispose();
int month = Integer.parseInt(textField.getText());
int year = Integer.parseInt(textField1.getText());
distributor.report(month, year);
}
});
}
});
AcceptPaymentButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
frame.setTitle("Find Subscription");
frame.setIconImage(new ImageIcon("adsiz2.png").getImage());
frame.getContentPane().setBackground(new Color(118, 217, 213));
frame.setLayout(new GridLayout(4, 1, 30, 18));
frame.setSize(300, 200);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
TextField textField = new TextField("Enter name of subscriber");
TextField textField1 = new TextField("Enter journal ISSN");
TextField textField2 = new TextField("Enter amount");
JButton button = new JButton("Confirm");
frame.add(textField);
frame.add(textField1);
frame.add(textField2);
frame.add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = textField.getText();
String ISSN = textField1.getText();
double amount = Double.parseDouble(textField2.getText());
Journal journal = distributor.searchJournal(ISSN);
if (journal == null) {
JOptionPane.showMessageDialog(null, "Journal #" + ISSN + " cannot be found!", "Error", JOptionPane.ERROR_MESSAGE);
frame.dispose();
return;
}
Subscriber subscriber = distributor.searchSubscriber(name);
if (subscriber == null) {
JOptionPane.showMessageDialog(null, "Subscriber " + name + " cannot be found!", "Error", JOptionPane.ERROR_MESSAGE);
frame.dispose();
return;
}
for (Subscription s : journal.getSubscriptions()) {
if (s.getSubscriber() == subscriber) {
s.getPayment().increasePayment(amount);
JOptionPane.showMessageDialog(null, "Added amount : " + amount + "$ Total received payment : " + s.getPayment().getReceivedPayment() + "$", "Payment accepted", JOptionPane.INFORMATION_MESSAGE);
frame.dispose();
return;
}
}
JOptionPane.showMessageDialog(null, "An error occurred while payment! Check ISSN & name!", "Error", JOptionPane.ERROR_MESSAGE);
frame.dispose();
return;
}
});
}
});
}
public static void main(String[] args) {
Distributor distributor = new Distributor();
/*
*
Individual individual = new Individual("Bora Ilci", "Bursa/Turkey", "011035", 9, 26, 635);
Individual individual1 = new Individual("Novak Djokovic", "Belgrad/Serbia", "011050", 3, 24, 504);
Individual individual2 = new Individual("Sebastian Vettel", "Heppenheim/Germany", "011092", 5, 28, 186);
Corporation corporation = new Corporation("From Software", "Tokyo/Japan", 9645789, "Development Bank of Japan", 4, 10, 2023, 21011001);
Journal journal = new Journal("Sports", "1001", 12, 6.49);
Journal journal1 = new Journal("Formula 1", "1002", 6, 4.99);
Journal journal2 = new Journal("Tennis", "1003", 12, 5.49);
DateInfo dateInfo = new DateInfo(1, 2023); // bora
DateInfo dateInfo1 = new DateInfo(3, 2023); // novak
DateInfo dateInfo2 = new DateInfo(5, 2023); //seb
DateInfo dateInfo3 = new DateInfo(4, 2023); // ffrom
PaymentInfo paymentInfo = new PaymentInfo(0, 50);
PaymentInfo paymentInfo1 = new PaymentInfo(5, 30);
PaymentInfo paymentInfo2 = new PaymentInfo(5, 0);
PaymentInfo paymentInfo3 = new PaymentInfo(10, 80);
distributor.addJournal(journal);
distributor.addJournal(journal1);
distributor.addJournal(journal2);
distributor.addSubscriber(individual);
distributor.addSubscriber(individual1);
distributor.addSubscriber(individual2);
distributor.addSubscriber(corporation);
Subscription subscription = new Subscription(dateInfo, paymentInfo, 0, individual, journal); // bora
Subscription subscription1 = new Subscription(dateInfo1, paymentInfo1, 0, individual1, journal2); // novak
Subscription subscription2 = new Subscription(dateInfo2, paymentInfo2, 0, individual2, journal1); // seb
Subscription subscription3 = new Subscription(dateInfo3, paymentInfo3, 0, corporation, journal); // from soft
distributor.addSubscription(journal.getIssn(), individual, subscription);
distributor.addSubscription(journal2.getIssn(), individual1, subscription1);
distributor.addSubscription(journal1.getIssn(), individual2, subscription2);
distributor.addSubscription(journal.getIssn(), corporation, subscription3);*/
MainGUI gui = new MainGUI(distributor);
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer
* >>> IMPORTANT!! <<<
* DO NOT edit this method OR call it in your code!
*
* @noinspection ALL
*/
private void $$$setupUI$$$() {
panel1 = new JPanel();
panel1.setLayout(new GridLayoutManager(10, 7, new Insets(0, 0, 0, 0), -1, -1));
panel1.setAlignmentX(0.0f);
panel1.setAlignmentY(0.0f);
panel1.setBackground(new Color(-8988203));
panel1.setBorder(BorderFactory.createTitledBorder(null, "", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
panel2 = new JPanel();
panel2.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1));
panel2.setBackground(new Color(-8988203));
Font panel2Font = this.$$$getFont$$$(null, -1, -1, panel2.getFont());
if (panel2Font != null) panel2.setFont(panel2Font);
panel2.setForeground(new Color(-8988203));
panel1.add(panel2, new GridConstraints(0, 0, 1, 7, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
final JLabel label1 = new JLabel();
label1.setBackground(new Color(-8988203));
Font label1Font = this.$$$getFont$$$("Bookshelf Symbol 7", -1, 40, label1.getFont());
if (label1Font != null) label1.setFont(label1Font);
label1.setForeground(new Color(-16777216));
label1.setText("Socrates Journal ");
panel2.add(label1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_SOUTHEAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JLabel label2 = new JLabel();
label2.setBackground(new Color(-8988203));
Font label2Font = this.$$$getFont$$$("Bookshelf Symbol 7", -1, 40, label2.getFont());
if (label2Font != null) label2.setFont(label2Font);
label2.setForeground(new Color(-16777216));
label2.setText("Distribution System ");
panel2.add(label2, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_NORTHEAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JLabel label3 = new JLabel();
label3.setIcon(new ImageIcon(getClass().getResource("/adsiz2.png")));
label3.setText("");
panel2.add(label3, new GridConstraints(0, 0, 2, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JLabel label4 = new JLabel();
label4.setBackground(new Color(-16777216));
Font label4Font = this.$$$getFont$$$("Bookshelf Symbol 7", Font.BOLD, 20, label4.getFont());
if (label4Font != null) label4.setFont(label4Font);
label4.setForeground(new Color(-16777216));
label4.setText("Subscription Operations");
panel1.add(label4, new GridConstraints(5, 0, 1, 7, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JLabel label5 = new JLabel();
label5.setBackground(new Color(-8988203));
Font label5Font = this.$$$getFont$$$("Bookshelf Symbol 7", Font.BOLD, 20, label5.getFont());
if (label5Font != null) label5.setFont(label5Font);
label5.setForeground(new Color(-16777216));
label5.setText("Subscriber Operations");
panel1.add(label5, new GridConstraints(3, 0, 1, 7, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JLabel label6 = new JLabel();
label6.setBackground(new Color(-8988203));
Font label6Font = this.$$$getFont$$$("Bookshelf Symbol 7", Font.BOLD, 20, label6.getFont());
if (label6Font != null) label6.setFont(label6Font);
label6.setForeground(new Color(-16777216));
label6.setText("Journal Operations");
panel1.add(label6, new GridConstraints(1, 0, 1, 7, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
AcceptPaymentButton = new JButton();
AcceptPaymentButton.setText("Accept Payment");
panel1.add(AcceptPaymentButton, new GridConstraints(6, 2, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JLabel label7 = new JLabel();
label7.setBackground(new Color(-16777216));
Font label7Font = this.$$$getFont$$$("Bookshelf Symbol 7", Font.BOLD, 20, label7.getFont());
if (label7Font != null) label7.setFont(label7Font);
label7.setForeground(new Color(-16777216));
label7.setText("Order Operations");
panel1.add(label7, new GridConstraints(7, 0, 1, 7, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
listAllSendingOrdersButton = new JButton();
listAllSendingOrdersButton.setText("List All Sending Orders");
panel1.add(listAllSendingOrdersButton, new GridConstraints(8, 1, 1, 5, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
createJournalButton = new JButton();
createJournalButton.setRequestFocusEnabled(false);
createJournalButton.setText("Create Journal");
panel1.add(createJournalButton, new GridConstraints(2, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
searchJournalButton = new JButton();
searchJournalButton.setText("Search Journal");
panel1.add(searchJournalButton, new GridConstraints(2, 4, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
createSubscriberButton = new JButton();
createSubscriberButton.setText("Create Subscriber");
panel1.add(createSubscriberButton, new GridConstraints(4, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
searchSubscriberButton = new JButton();
searchSubscriberButton.setText("Search Subscriber");
panel1.add(searchSubscriberButton, new GridConstraints(4, 4, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
reportStateButton = new JButton();
reportStateButton.setText("Report State");
panel1.add(reportStateButton, new GridConstraints(9, 3, 1, 1, GridConstraints.ANCHOR_NORTH, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
createSubscriptionButton = new JButton();
createSubscriptionButton.setText("Create Subscription");
panel1.add(createSubscriptionButton, new GridConstraints(6, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
listSubscriptionsButton = new JButton();
listSubscriptionsButton.setText("List Subscriptions");
panel1.add(listSubscriptionsButton, new GridConstraints(6, 5, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
listIncompletePaymentsButton = new JButton();
listIncompletePaymentsButton.setText("List Incomplete Payments");
panel1.add(listIncompletePaymentsButton, new GridConstraints(8, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
listSendingOrdersButton = new JButton();
listSendingOrdersButton.setText("List Sending Orders");
panel1.add(listSendingOrdersButton, new GridConstraints(8, 6, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
saveStateButton = new JButton();
saveStateButton.setText("Save State");
panel1.add(saveStateButton, new GridConstraints(9, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
loadStateButton = new JButton();
loadStateButton.setText("Load State");
panel1.add(loadStateButton, new GridConstraints(9, 6, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
}
/**
* @noinspection ALL
*/
private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) {
if (currentFont == null) return null;
String resultName;
if (fontName == null) {
resultName = currentFont.getName();
} else {
Font testFont = new Font(fontName, Font.PLAIN, 10);
if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
resultName = fontName;
} else {
resultName = currentFont.getName();
}
}
Font font = new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize());
boolean isMac = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).startsWith("mac");
Font fontWithFallback = isMac ? new Font(font.getFamily(), font.getStyle(), font.getSize()) : new StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize());
return fontWithFallback instanceof FontUIResource ? fontWithFallback : new FontUIResource(fontWithFallback);
}
/**
* @noinspection ALL
*/
public JComponent $$$getRootComponent$$$() {
return panel1;
}
}