-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyThread.java
84 lines (76 loc) · 4.12 KB
/
MyThread.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
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.util.Vector;
public class MyThread extends Thread {
private int month, year;
private Distributor distributor;
private StringBuilder string;
private JFrame frame;
public MyThread(int month, int year, Distributor distributor, JFrame frame) {
this.month = month;
this.year = year;
this.distributor = distributor;
string = new StringBuilder();
this.frame = frame;
}
@Override
public void run() {
int count = 0;
Vector<Vector<String>> stringList = new Vector<>();
for (String key : distributor.getJournals().keySet()) {
for (Subscription s : distributor.getJournals().get(key).getSubscriptions()) {
if (s.getDates().getStartYear() == year && month >= s.getDates().getStartMonth()) {
Vector<String> temp = new Vector<>();
temp.add(s.getSubscriber().getName());
if (s.getSubscriber() instanceof Individual) {
temp.add("Individual");
} else {
temp.add("Corporation");
}
temp.add(s.getSubscriber().getAddress());
temp.add(String.valueOf(s.getDates().getStartMonth()) + " / " + s.getDates().getStartYear());
if (s.getDates().getStartMonth() == 1) {
temp.add(String.valueOf(s.getDates().getEndMonth()) + " / " + s.getDates().getStartYear());
} else {
temp.add(String.valueOf(s.getDates().getEndMonth()) + " / " + (s.getDates().getStartYear() + 1));
}
temp.add(s.getJournal().getName());
double price = s.getJournal().getIssuePrice() * s.getJournal().getFrequency() * s.getCopies() * ((100 - s.getPayment().getDiscountRatio()) / 100.0);
temp.add(String.valueOf(price) + " $");
stringList.add(temp);
} else if (s.getDates().getStartYear() + 1 == year && month < s.getDates().getEndMonth() && s.getDates().getEndMonth() != 12) {
Vector<String> temp = new Vector<>();
temp.add(s.getSubscriber().getName());
if (s.getSubscriber() instanceof Individual) {
temp.add("Individual");
} else {
temp.add("Corporation");
}
temp.add(s.getSubscriber().getAddress());
temp.add(String.valueOf(s.getDates().getStartMonth()) + " / " + s.getDates().getStartYear());
if (s.getDates().getStartMonth() == 1) {
temp.add(String.valueOf(s.getDates().getEndMonth()) + " / " + s.getDates().getStartYear());
} else {
temp.add(String.valueOf(s.getDates().getEndMonth()) + " / " + (s.getDates().getStartYear() + 1));
}
temp.add(s.getJournal().getName());
double price = s.getJournal().getIssuePrice() * s.getJournal().getFrequency() * s.getCopies() * ((100 - s.getPayment().getDiscountRatio()) / 100.0);
temp.add(String.valueOf(price) + " $");
stringList.add(temp);
}
}
}
DefaultTableModel tableModel = new DefaultTableModel(0, 7); // 0 rows, 5 columns
tableModel.setColumnIdentifiers(new Object[]{"Subscriber Name", "Subscriber Type", "Subscriber Address", "Start Date", "End Date", "Journal Name", "Annual Payment"});
JTable table = new JTable(tableModel);
stringList.forEach(tableModel::addRow);
JScrollPane jScrollPane = new JScrollPane(table);
frame.getContentPane().add(jScrollPane);
frame.setSize(850, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
table.setPreferredSize(new Dimension(850, 400));
table.setRowHeight(30);
}
}