-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSignUp.java
342 lines (269 loc) · 9.82 KB
/
SignUp.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
package DoctorsAP;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.filechooser.FileNameExtensionFilter;
public class SignUp {
private JFrame frame;
private JTextField id_P;
private JTextField Name_P;
private JTextField password_P;
private JButton BTNforPatient;
Connection connection = null;
private JLabel lblSignUp;
private JLabel lblCreateAFree;
private JTextField Address_P;
private JTextField Phone_P;
private JTextField id_D;
private JTextField Name_D;
private JTextField password_D;
private JTextField Address_D;
private JTextField Phone_D;
private JTextField Photo_D;
private JTextField Catagory_D;
private JLabel label_6;
String s;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SignUp window = new SignUp();
window.frame.setVisible(true);
window.frame.setResizable(false);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
SignUp() {
connection = SQLconnection.dbConnector();
frame = new JFrame();
frame.setBounds(100, 100, 598, 566);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().setLayout(null);
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setBorder(null);
panel.setBackground(new Color(0, 0, 0, 100));
panel.setBounds(10, 125, 558, 352);
frame.getContentPane().add(panel);
JLabel lblNewLabel = new JLabel("Patient's ID");
lblNewLabel.setForeground(Color.WHITE);
lblNewLabel.setBounds(10, 38, 161, 29);
panel.add(lblNewLabel);
Name_P = new JTextField();
Name_P.setBounds(106, 78, 133, 25);
panel.add(Name_P);
Name_P.setColumns(10);
password_P = new JTextField();
password_P.setBounds(106, 114, 133, 25);
panel.add(password_P);
password_P.setColumns(10);
id_P = new JTextField();
id_P.setBounds(106, 42, 133, 25);
panel.add(id_P);
id_P.setColumns(10);
JLabel lblUser = new JLabel("Patient's Name");
lblUser.setForeground(Color.WHITE);
lblUser.setBounds(10, 74, 161, 29);
panel.add(lblUser);
JLabel lblPassword = new JLabel("Password");
lblPassword.setForeground(Color.WHITE);
lblPassword.setBounds(10, 114, 161, 29);
panel.add(lblPassword);
BTNforPatient = new JButton("Create Account");
BTNforPatient.setBounds(106, 268, 133, 29);
panel.add(BTNforPatient);
JLabel lblAddress = new JLabel("Address");
lblAddress.setForeground(Color.WHITE);
lblAddress.setBounds(10, 154, 161, 29);
panel.add(lblAddress);
JLabel lblPhone = new JLabel("Phone");
lblPhone.setForeground(Color.WHITE);
lblPhone.setBounds(10, 188, 161, 29);
panel.add(lblPhone);
JLabel lblPhoto = new JLabel("photo");
lblPhoto.setForeground(Color.WHITE);
lblPhoto.setBounds(10, 228, 161, 29);
panel.add(lblPhoto);
Address_P = new JTextField();
Address_P.setColumns(10);
Address_P.setBounds(106, 158, 133, 25);
panel.add(Address_P);
Phone_P = new JTextField();
Phone_P.setColumns(10);
Phone_P.setBounds(106, 194, 133, 25);
panel.add(Phone_P);
JLabel lblDoctorsId = new JLabel("Doctor's ID");
lblDoctorsId.setForeground(Color.WHITE);
lblDoctorsId.setBounds(258, 38, 161, 29);
panel.add(lblDoctorsId);
id_D = new JTextField();
id_D.setColumns(10);
id_D.setBounds(354, 42, 133, 25);
panel.add(id_D);
JLabel lblDoctorsName = new JLabel("Doctor's Name");
lblDoctorsName.setForeground(Color.WHITE);
lblDoctorsName.setBounds(258, 74, 161, 29);
panel.add(lblDoctorsName);
Name_D = new JTextField();
Name_D.setColumns(10);
Name_D.setBounds(354, 78, 133, 25);
panel.add(Name_D);
JLabel label_2 = new JLabel("Password");
label_2.setForeground(Color.WHITE);
label_2.setBounds(258, 114, 161, 29);
panel.add(label_2);
password_D = new JTextField();
password_D.setColumns(10);
password_D.setBounds(354, 114, 133, 25);
panel.add(password_D);
JLabel label_3 = new JLabel("Address");
label_3.setForeground(Color.WHITE);
label_3.setBounds(258, 154, 161, 29);
panel.add(label_3);
Address_D = new JTextField();
Address_D.setColumns(10);
Address_D.setBounds(354, 158, 133, 25);
panel.add(Address_D);
JLabel label_4 = new JLabel("Phone");
label_4.setForeground(Color.WHITE);
label_4.setBounds(258, 188, 161, 29);
panel.add(label_4);
Phone_D = new JTextField();
Phone_D.setColumns(10);
Phone_D.setBounds(354, 194, 133, 25);
panel.add(Phone_D);
JLabel label_5 = new JLabel("photo");
label_5.setForeground(Color.WHITE);
label_5.setBounds(258, 271, 161, 29);
panel.add(label_5);
Photo_D = new JTextField();
Photo_D.setColumns(10);
Photo_D.setBounds(354, 273, 133, 25);
panel.add(Photo_D);
JButton browse = new JButton("browse");
browse.setToolTipText("Browse for photos");
browse.setBounds(106, 237, 133, 23);
panel.add(browse);
browse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
FileNameExtensionFilter filter = new FileNameExtensionFilter("*.IMAGE", "jpg","gif","png");
fileChooser.addChoosableFileFilter(filter);
int result = fileChooser.showSaveDialog(null);
if(result == JFileChooser.APPROVE_OPTION){
File selectedFile = fileChooser.getSelectedFile();
String path = selectedFile.getAbsolutePath();
//lblNoImage.setIcon(ResizeImage(path, null));
s = path;
}
else if(result == JFileChooser.CANCEL_OPTION){
System.out.println("No Data");
}
}
});
JButton BTNforDoctors = new JButton("Create Account");
BTNforDoctors.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
String query= "insert into d_registration(NAME_D, ID_D, PASSWORD_D, ADDRESS_D, PHONE_D, PHOTO_D, CATAGORY_D) values(?,?,?,?,?,?,?)";
PreparedStatement pst = connection.prepareStatement(query);
pst.setString(1, Name_D.getText());
pst.setString(2, id_D.getText());
pst.setString(3, password_D.getText());
pst.setString(4, Catagory_D.getText());
pst.setString(5, Phone_D.getText());
pst.setString(6, Address_D.getText());
pst.setString(7, Photo_D.getText());
pst.execute();
JOptionPane.showMessageDialog(null, "data saved");
pst.close();
} catch (Exception e2) {
e2.printStackTrace();
JOptionPane.showMessageDialog(null, "Use different ID");
}
}
});
BTNforDoctors.setBounds(354, 311, 133, 29);
panel.add(BTNforDoctors);
Catagory_D = new JTextField();
Catagory_D.setColumns(10);
Catagory_D.setBounds(354, 232, 133, 25);
panel.add(Catagory_D);
label_6 = new JLabel("Catagory");
label_6.setForeground(Color.WHITE);
label_6.setBounds(258, 228, 161, 29);
panel.add(label_6);
BTNforPatient.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String query= "insert into p_registration(NAME_P, ID_P, PASSWORD_P, ADDRESS_P, PHONE_P, PHOTO_P) values(?,?,?,?,?,?)";
PreparedStatement pst = connection.prepareStatement(query);
pst.setString(1, Name_P.getText());
pst.setString(2, id_P.getText());
pst.setString(3, password_P.getText());
pst.setString(4, Address_P.getText());
pst.setString(5, Phone_P.getText());
InputStream img = new FileInputStream(new File(s));
pst.setBlob(6,img);
if(pst.executeUpdate() == 1)
{
JOptionPane.showMessageDialog(null, "data Inserted");
}
else{
JOptionPane.showMessageDialog(null, "No Image Selected");
}
pst.close();
} catch (Exception e2) {
e2.printStackTrace();
JOptionPane.showMessageDialog(null, "Use different ID");
}
}
});
JButton button = new JButton("<<");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Main_Window window = new Main_Window();
window.frame.setVisible(true);
window.frame.setResizable(false);
frame.dispose();
}
});
button.setBounds(10, 11, 130, 25);
frame.getContentPane().add(button);
lblCreateAFree = new JLabel("Create a free Account");
lblCreateAFree.setHorizontalAlignment(SwingConstants.CENTER);
lblCreateAFree.setForeground(Color.WHITE);
lblCreateAFree.setFont(new Font("Tahoma", Font.BOLD, 35));
lblCreateAFree.setBounds(10, 65, 558, 63);
frame.getContentPane().add(lblCreateAFree);
lblSignUp = new JLabel("");
lblSignUp.setFont(new Font("Tahoma", Font.PLAIN, 10));
lblSignUp.setBackground(new Color(51, 0, 102));
//lblSignUp.setIcon(new ImageIcon(LogIn_window.class.getResource("/Photos/SignUp.jpg")));
lblSignUp.setBounds(0, 0, 659, 543);
frame.getContentPane().add(lblSignUp);
}
}