-
Notifications
You must be signed in to change notification settings - Fork 3
/
AddStudent.java
199 lines (159 loc) · 6.78 KB
/
AddStudent.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
package university.management.system;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import com.toedter.calendar.JDateChooser;
import java.awt.event.*;
public class AddStudent extends JFrame implements ActionListener{
JTextField tfname, tffname, tfaddress, tfphone, tfemail, tfx, tfxii, tcnic;
JLabel labelrollno;
JDateChooser dcdob;
JComboBox cbcourse, cbbranch;
JButton submit, cancel;
Random ran = new Random();
long first4 = Math.abs((ran.nextLong() % 9000L) + 1000L);
AddStudent() {
setSize(900, 700);
setLocation(350, 50);
setLayout(null);
JLabel heading = new JLabel("New Student Details");
heading.setBounds(310, 30, 500, 50);
heading.setFont(new Font("serif", Font.BOLD, 30));
// heading.setFont(new Font("consolas",Font.BOLD,30));
add(heading);
JLabel lblname = new JLabel("Name");
lblname.setBounds(50, 150, 100, 30);
lblname.setFont(new Font("serif", Font.BOLD, 20));
add(lblname);
tfname = new JTextField();
tfname.setBounds(200, 150, 150, 30);
add(tfname);
JLabel lblfname = new JLabel("Father's Name");
lblfname.setBounds(400, 150, 200, 30);
lblfname.setFont(new Font("serif", Font.BOLD, 20));
add(lblfname);
tffname = new JTextField();
tffname.setBounds(600, 150, 150, 30);
add(tffname);
JLabel lblrollno = new JLabel("Roll Number");
lblrollno.setBounds(50, 200, 200, 30);
lblrollno.setFont(new Font("serif", Font.BOLD, 20));
add(lblrollno);
labelrollno = new JLabel("1533"+first4);
labelrollno.setBounds(200, 200, 200, 30);
labelrollno.setFont(new Font("serif", Font.BOLD, 20));
add(labelrollno);
JLabel lbldob = new JLabel("Date of Birth");
lbldob.setBounds(400, 200, 200, 30);
lbldob.setFont(new Font("serif", Font.BOLD, 20));
add(lbldob);
dcdob = new JDateChooser();
dcdob.setBounds(600, 200, 150, 30);
add(dcdob);
JLabel lbladdress = new JLabel("Address");
lbladdress.setBounds(50, 250, 200, 30);
lbladdress.setFont(new Font("serif", Font.BOLD, 20));
add(lbladdress);
tfaddress = new JTextField();
tfaddress.setBounds(200, 250, 150, 30);
add(tfaddress);
JLabel lblphone = new JLabel("Phone");
lblphone.setBounds(400, 250, 200, 30);
lblphone.setFont(new Font("serif", Font.BOLD, 20));
add(lblphone);
tfphone = new JTextField();
tfphone.setBounds(600, 250, 150, 30);
add(tfphone);
JLabel lblemail = new JLabel("Email Id");
lblemail.setBounds(50, 300, 200, 30);
lblemail.setFont(new Font("serif", Font.BOLD, 20));
add(lblemail);
tfemail = new JTextField();
tfemail.setBounds(200, 300, 150, 30);
add(tfemail);
JLabel lblx = new JLabel("Class X (P%)");
lblx.setBounds(400, 300, 200, 30);
lblx.setFont(new Font("serif", Font.BOLD, 20));
add(lblx);
tfx = new JTextField();
tfx.setBounds(600, 300, 150, 30);
add(tfx);
JLabel lblxii = new JLabel("Class XII (P%)");
lblxii.setBounds(50, 350, 200, 30);
lblxii.setFont(new Font("serif", Font.BOLD, 20));
add(lblxii);
tfxii = new JTextField();
tfxii.setBounds(200, 350, 150, 30);
add(tfxii);
JLabel lblcnic = new JLabel("CNIC Number");
lblcnic.setBounds(400, 350, 200, 30);
lblcnic.setFont(new Font("serif", Font.BOLD, 20));
add(lblcnic);
tcnic = new JTextField();
tcnic.setBounds(600, 350, 150, 30);
add(tcnic);
JLabel lblcourse = new JLabel("Course");
lblcourse.setBounds(50, 400, 200, 30);
lblcourse.setFont(new Font("serif", Font.BOLD, 20));
add(lblcourse);
String course[] = {"B.Tech", "BBA", "BCA", "Bsc", "Msc", "MBA", "MCA", "MCom", "MA", "BA"};
cbcourse = new JComboBox(course);
cbcourse.setBounds(200, 400, 150, 30);
cbcourse.setBackground(Color.WHITE);
add(cbcourse);
JLabel lblbranch = new JLabel("Branch");
lblbranch.setBounds(400, 400, 200, 30);
lblbranch.setFont(new Font("serif", Font.BOLD, 20));
add(lblbranch);
String branch[] = {"Computer Science", "Electronics", "Mechanical", "Civil", "IT"};
cbbranch = new JComboBox(branch);
cbbranch.setBounds(600, 400, 150, 30);
cbbranch.setBackground(Color.WHITE);
add(cbbranch);
submit = new JButton("Submit");
submit.setBounds(250, 550, 120, 30);
submit.setBackground(Color.BLACK);
submit.setForeground(Color.WHITE);
submit.addActionListener(this);
submit.setFont(new Font("Tahoma", Font.BOLD, 15));
add(submit);
cancel = new JButton("Cancel");
cancel.setBounds(450, 550, 120, 30);
cancel.setBackground(Color.BLACK);
cancel.setForeground(Color.WHITE);
cancel.addActionListener(this);
cancel.setFont(new Font("Tahoma", Font.BOLD, 15));
add(cancel);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == submit) {
String name = tfname.getText();
String fname = tffname.getText();
String rollno = labelrollno.getText();
String dob = ((JTextField) dcdob.getDateEditor().getUiComponent()).getText();
String address = tfaddress.getText();
String phone = tfphone.getText();
String email = tfemail.getText();
String x = tfx.getText();
String xii = tfxii.getText();
String cnic = tcnic.getText();
String course = (String) cbcourse.getSelectedItem();
String branch = (String) cbbranch.getSelectedItem();
try {
String query = "insert into student values('"+name+"', '"+fname+"', '"+rollno+"', '"+dob+"', '"+address+"', '"+phone+"', '"+email+"', '"+x+"', '"+xii+"', '"+cnic+"', '"+course+"', '"+branch+"')";
Conn con = new Conn();
con.s.executeUpdate(query);
JOptionPane.showMessageDialog(null, "Student Details Inserted Successfully");
setVisible(false);
} catch (Exception e) {
e.printStackTrace();
}
} else {
setVisible(false);
}
}
public static void main(String[] args) {
new AddStudent();
}
}