-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappsView.java
215 lines (165 loc) · 6.07 KB
/
appsView.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
import java.awt.GridLayout;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class appsView extends JFrame {
private static final long serialVersionUID = 1L;
boolean createNewButtonFlag = false;
boolean deleteFlag = false;
boolean printPrescriptionFlag = true;
boolean symptomsFlag = true;
user userLogged = null;
appsController L = null;
appsModel M = null;
login loginPage = null;
homeView homePage = null;
JTable apps = null;
JTextField nameTF = null;
JTextField surnameTF = null;
JTextField doctorTF = null;
JTextField dateTF = null;
JTextField timeTF = null;
JTextArea symptomsTF = null;
JPanel left = null;
public appsView(user userRef, login loginRef, homeView homeRef){
this.setSize(1000,600); // This is the frame, the numbers are the size of the windows
this.setTitle("Appointments"); // Setting the title of the window
this.setVisible(true); // We're saying to the window to show itself
userLogged = userRef;
M = new appsModel(userLogged, this);
loginPage = loginRef;
homePage = homeRef;
L = new appsController(M, this, loginPage, homePage);
JMenuBar bar = new JMenuBar(); // Creating a menu bar
this.setJMenuBar(bar);
JMenu file = new JMenu("File"); // Creating a menu tab
bar.add(file); // Sticking the menu tab to the menu bar
JMenuItem logout = new JMenuItem("Logout");
file.add(logout);
logout.addActionListener(L);
logout.setActionCommand("logout");
JMenuItem backHome = new JMenuItem("Back to home");
file.add(backHome);
backHome.addActionListener(L);
backHome.setActionCommand("backHome");
if (userLogged.getType().equals("Receptionist")){
createNewButtonFlag = true;
deleteFlag = true;
printPrescriptionFlag = false;
symptomsFlag = false;
}
this.setLayout(new GridLayout(0,2));
left = new JPanel();
this.add(left);
drawingTable();
JPanel right = new JPanel();
this.add(right);
JLabel nameLabel = new JLabel("Name");
nameTF = new JTextField(10);
JLabel surnameLabel = new JLabel("Surname");
surnameTF = new JTextField(10);
JLabel doctorLabel = new JLabel("Doctor");
doctorTF = new JTextField(10);
JLabel dateLabel = new JLabel("Date");
dateTF = new JTextField(10);
JLabel timeLabel = new JLabel("Time");
timeTF = new JTextField(10);
JLabel symptomsLabel = new JLabel("Symptoms");
symptomsLabel.setVisible(symptomsFlag);
symptomsTF = new JTextArea(10,10);
symptomsTF.setVisible(symptomsFlag);
JButton createNew = new JButton("Create New");
createNew.setVisible(createNewButtonFlag);
createNew.addActionListener(L);
createNew.setActionCommand("createNew");
JButton save = new JButton("Save");
save.addActionListener(L);
save.setActionCommand("save");
JButton delete = new JButton("Delete");
delete.setVisible(deleteFlag);;
delete.addActionListener(L);
delete.setActionCommand("delete");
JButton prescription = new JButton("Prescription");
prescription.setVisible(printPrescriptionFlag);
prescription.addActionListener(L);
prescription.setActionCommand("prescription");
GroupLayout layout = new GroupLayout(right);
right.setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup(
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(nameLabel)
.addComponent(surnameLabel)
.addComponent(doctorLabel)
.addComponent(dateLabel)
.addComponent(timeLabel)
.addComponent(symptomsLabel))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(nameTF)
.addComponent(surnameTF)
.addComponent(doctorTF)
.addComponent(dateTF)
.addComponent(timeTF)
.addComponent(symptomsTF)
.addGroup(layout.createSequentialGroup()
.addComponent(createNew)
.addComponent(save)
.addComponent(delete)
.addComponent(prescription)))
);
layout.setVerticalGroup(
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(nameLabel)
.addComponent(nameTF))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(surnameLabel)
.addComponent(surnameTF))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(doctorLabel)
.addComponent(doctorTF))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(dateLabel)
.addComponent(dateTF))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(timeLabel)
.addComponent(timeTF))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(symptomsLabel)
.addComponent(symptomsTF))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(createNew)
.addComponent(save)
.addComponent(delete)
.addComponent(prescription))
);
validate();
repaint();
}
public JTable getTable() {
return apps;
}
public void drawingTable(){
left.removeAll();
apps = null;
String[] columnNames = {"ID","Name","Surname","Date","Time"};
Object [][] data = M.queryForView();
apps = new JTable(data, columnNames);
apps.getSelectionModel().addListSelectionListener(L);
JScrollPane js=new JScrollPane(apps);
left.add(js);
this.validate();
this.repaint();
}
}