-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaskingWhich.java
163 lines (100 loc) · 3.63 KB
/
askingWhich.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
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class askingWhich extends JFrame implements ActionListener, ListSelectionListener{
private static final long serialVersionUID = 1L;
JTable options = null;
int counter = 0;
String answer = null;
msgsModel msgsModelPage = null;
appsModel appsModelPage = null;
billsModel billsModelPage = null;
ResultSet rs = null;
Object [][] opt = new Object [100][3];
public askingWhich(String question, String name, String surname, msgsModel msgsModelRef, appsModel appsModelRef, billsModel billsModelRef){
msgsModelPage = msgsModelRef;
appsModelPage = appsModelRef;
billsModelPage = billsModelRef;
String dbQuery = "SELECT * FROM `surgery`.`patients` WHERE (`Name` = '"+name+"' AND `Surname` = '"+surname+"');";
database DB = new database ();
rs = (ResultSet) DB.accessDB(dbQuery);
storingOptions();
this.setSize(500,300); // This is the frame, the numbers are the size of the windows
this.setTitle("Question"); // Setting the title of the window
this.setVisible(true); // We're saying to the window to show itself
this.setLayout(new GridLayout(3,0));
JPanel first = new JPanel();
this.add(first);
JLabel questionLabel = new JLabel (question); // ASK KYLE
first.add(questionLabel);
String[] columnNames = {"ID","Name","Surname"};
options = new JTable(opt, columnNames);
options.getSelectionModel().addListSelectionListener(this);
JScrollPane js=new JScrollPane(options);
this.add(js);
JPanel third = new JPanel();
this.add(third);
JButton cancel = new JButton("Cancel");
third.add(cancel);
cancel.addActionListener(this);
cancel.setActionCommand("cancel");
validate();
repaint();
}
public void storingOptions(){
try{
int rowCounter = 0;
while(rs.next()){
String id = rs.getString("ID_Pat");
String name = rs.getString("Name");
String surname = rs.getString("Surname");
opt [rowCounter][0] = id;
opt [rowCounter][1] = name;
opt [rowCounter][2] = surname;
rowCounter ++;
}
}
catch(SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("cancel")){
this.setVisible(false);
}
}
public void valueChanged(ListSelectionEvent arg0) {
counter ++;
if (counter == 2){
String id = (String) options.getValueAt(options.getSelectedRow(), 0);
answer = id;
this.setVisible(false);
if (msgsModelPage != null){
msgsModelPage.newEntry();
}
else if (appsModelPage != null){
appsModelPage.newEntry();
}
else if (billsModelPage != null){
billsModelPage.newEntry();
}
counter = 0;
}
}
public String getAnswer(){
return answer;
}
}