1
+ package Admin ;
2
+
3
+ import java .awt .BorderLayout ;
4
+ import java .awt .EventQueue ;
5
+ import java .awt .Font ;
6
+ import java .awt .Toolkit ;
7
+ import java .awt .event .ActionEvent ;
8
+ import java .awt .event .ActionListener ;
9
+ import java .sql .DriverManager ;
10
+ import java .sql .ResultSet ;
11
+
12
+ import javax .swing .ButtonGroup ;
13
+ import javax .swing .JButton ;
14
+ import javax .swing .JComboBox ;
15
+ import javax .swing .JFrame ;
16
+ import javax .swing .JLabel ;
17
+ import javax .swing .JOptionPane ;
18
+ import javax .swing .JPanel ;
19
+ import javax .swing .JRadioButton ;
20
+ import javax .swing .JTextArea ;
21
+ import javax .swing .border .EmptyBorder ;
22
+
23
+ import com .mysql .jdbc .Connection ;
24
+ import com .mysql .jdbc .PreparedStatement ;
25
+ /**
26
+ *
27
+ * @author Soumyadip Chowdhury
28
+ * @github soumyadip007
29
+ *
30
+ */
31
+ public class Add extends JFrame {
32
+
33
+ private JPanel contentPane ;
34
+
35
+ /**
36
+ * Launch the application.
37
+ */
38
+ public static void main (String [] args ) {
39
+ EventQueue .invokeLater (new Runnable () {
40
+ public void run () {
41
+ try {
42
+ Add frame = new Add ();
43
+ frame .setVisible (true );
44
+ } catch (Exception e ) {
45
+ e .printStackTrace ();
46
+ }
47
+ }
48
+ });
49
+ }
50
+
51
+ /**
52
+ * Create the frame.
53
+ */
54
+ public Add () {
55
+ setIconImage (Toolkit .getDefaultToolkit ().getImage ("C:\\ Users\\ Soumyadeep\\ Desktop\\ Book Hub\\ 0 (Custom).jpg" ));
56
+
57
+ //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
58
+ setBounds (450 , 319 , 1014 , 460 );
59
+ setResizable (false );
60
+ contentPane = new JPanel ();
61
+ contentPane .setBorder (new EmptyBorder (5 , 5 , 5 , 5 ));
62
+ setContentPane (contentPane );
63
+ contentPane .setLayout (null );
64
+
65
+ JLabel lblNewLabel = new JLabel ("Name" );
66
+ lblNewLabel .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
67
+ lblNewLabel .setBounds (59 , 25 , 145 , 32 );
68
+ contentPane .add (lblNewLabel );
69
+
70
+ JLabel lblGurdiansName = new JLabel ("Contact(Email/Ph)" );
71
+ lblGurdiansName .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
72
+ lblGurdiansName .setBounds (59 , 107 , 164 , 32 );
73
+ contentPane .add (lblGurdiansName );
74
+
75
+ JLabel lblGender = new JLabel ("I'll come next time" );
76
+ lblGender .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
77
+ lblGender .setBounds (59 , 184 , 179 , 32 );
78
+ contentPane .add (lblGender );
79
+
80
+ JTextArea stuname = new JTextArea ();
81
+ stuname .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
82
+ stuname .setBounds (235 , 26 , 166 , 37 );
83
+ contentPane .add (stuname );
84
+
85
+ JTextArea partname = new JTextArea ();
86
+ partname .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
87
+ partname .setBounds (235 , 102 , 166 , 37 );
88
+ contentPane .add (partname );
89
+
90
+ JRadioButton rdbtnNewRadioButton = new JRadioButton ("Yes" );
91
+ rdbtnNewRadioButton .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
92
+ rdbtnNewRadioButton .setBounds (235 , 172 , 75 , 44 );
93
+ contentPane .add (rdbtnNewRadioButton );
94
+
95
+ JRadioButton rdbtnNewRadioButton_1 = new JRadioButton ("No" );
96
+ rdbtnNewRadioButton_1 .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
97
+ rdbtnNewRadioButton_1 .setBounds (235 , 213 , 138 , 40 );
98
+ contentPane .add (rdbtnNewRadioButton_1 );
99
+ ButtonGroup btg =new ButtonGroup ();
100
+ btg .add (rdbtnNewRadioButton_1 );
101
+ btg .add (rdbtnNewRadioButton );
102
+
103
+
104
+ JLabel lblDob = new JLabel ("Next Meetup" );
105
+ lblDob .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
106
+ lblDob .setBounds (481 , 25 , 158 , 32 );
107
+ contentPane .add (lblDob );
108
+
109
+ JComboBox date = new JComboBox ();
110
+ for (int i =1 ;i <=31 ;i ++)
111
+ {
112
+ String str =String .valueOf (i );
113
+ date .addItem (str );
114
+ }
115
+ date .setBounds (662 , 32 , 48 , 27 );
116
+ contentPane .add (date );
117
+
118
+ JComboBox month = new JComboBox ();
119
+ month .setBounds (739 , 32 , 75 , 27 );
120
+ month .addItem ("Jan" );
121
+ month .addItem ("Feb" );
122
+ month .addItem ("Mar" );
123
+ month .addItem ("Apr" );
124
+ month .addItem ("May" );
125
+ month .addItem ("Jun" );
126
+ month .addItem ("Jul" );
127
+ month .addItem ("Aug" );
128
+ month .addItem ("Sep" );
129
+ month .addItem ("Oct" );
130
+ month .addItem ("Nov" );
131
+ month .addItem ("Dec" );
132
+ contentPane .add (month );
133
+ /**
134
+ *
135
+ * @author Soumyadip Chowdhury
136
+ * @github soumyadip007
137
+ *
138
+ */
139
+ JComboBox year = new JComboBox ();
140
+ for (int i =1901 ;i <=2018 ;i ++)
141
+ {
142
+ String str =String .valueOf (i );
143
+ year .addItem (str );
144
+ }
145
+ year .setBounds (841 , 32 , 109 , 27 );
146
+ contentPane .add (year );
147
+
148
+ JLabel lblRollNo = new JLabel ("0-5 Star (Ambiance)" );
149
+ lblRollNo .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
150
+ lblRollNo .setBounds (483 , 184 , 209 , 32 );
151
+ contentPane .add (lblRollNo );
152
+
153
+ JLabel lblClassTeacher = new JLabel ("0-5 Star (Overall)" );
154
+ lblClassTeacher .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
155
+ lblClassTeacher .setBounds (481 , 261 , 158 , 32 );
156
+ contentPane .add (lblClassTeacher );
157
+
158
+ JTextArea roll = new JTextArea ();
159
+ roll .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
160
+ roll .setBounds (662 , 185 , 166 , 37 );
161
+ contentPane .add (roll );
162
+
163
+ JLabel lblSection = new JLabel ("0-5 Star (Service)" );
164
+ lblSection .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
165
+ lblSection .setBounds (481 , 107 , 169 , 32 );
166
+ contentPane .add (lblSection );
167
+
168
+ JTextArea teacher = new JTextArea ();
169
+ teacher .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
170
+ teacher .setBounds (662 , 262 , 166 , 37 );
171
+ contentPane .add (teacher );
172
+
173
+ JLabel lblClass = new JLabel ("Reivew" );
174
+ lblClass .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
175
+ lblClass .setBounds (59 , 261 , 145 , 32 );
176
+ contentPane .add (lblClass );
177
+
178
+ JTextArea stuclass = new JTextArea ();
179
+ stuclass .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
180
+ stuclass .setBounds (235 , 262 , 166 , 37 );
181
+ contentPane .add (stuclass );
182
+
183
+ JTextArea section = new JTextArea ();
184
+ section .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
185
+ section .setBounds (662 , 110 , 166 , 37 );
186
+ contentPane .add (section );
187
+
188
+ JButton btnNewButton = new JButton ("Add" );
189
+ btnNewButton .addActionListener (new ActionListener () {
190
+ /* (non-Javadoc)
191
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
192
+ */
193
+ public void actionPerformed (ActionEvent e ) {
194
+ int a =JOptionPane .showConfirmDialog (btnNewButton ,"Are you sure?" );
195
+ //JOptionPane.setRootFrame(null);
196
+ if (a ==JOptionPane .YES_OPTION ){
197
+
198
+ String name =stuname .getText ();
199
+ String prnt = partname .getText ();
200
+
201
+ String condition ="" ;
202
+ if (rdbtnNewRadioButton .isSelected ())
203
+ {
204
+ condition ="Male" ;
205
+
206
+ }
207
+ else if (rdbtnNewRadioButton_1 .isSelected ())
208
+ {
209
+ condition ="Female" ;
210
+
211
+ }
212
+ int i =1 ;
213
+ String cls =stuclass .getText ();
214
+ String rl =roll .getText ();
215
+ String tch =teacher .getText ();
216
+ String sec =section .getText ();
217
+
218
+
219
+ String dt =(String ) date .getSelectedItem ();
220
+ String mnth =(String ) month .getSelectedItem ();
221
+ String yr =(String ) year .getSelectedItem ();
222
+
223
+ String date =dt +"/" +mnth +"/" +yr ;
224
+ try {
225
+ System .out .println ("add" );
226
+
227
+ Class .forName ("com.mysql.jdbc.Driver" );
228
+
229
+ Connection con =(Connection ) DriverManager .getConnection ("jdbc:mysql://localhost:3306/school" ,"root" ,"" );
230
+
231
+ PreparedStatement st =(PreparedStatement ) con .prepareStatement ("INSERT INTO stu(name,prt,gender,class,dob,section,teach,roll,pass) values(?,?,?,?,?,?,?,?,?)" );
232
+
233
+ st .setString (1 , name );
234
+ st .setString (2 , prnt );
235
+ st .setString (3 , condition );
236
+ st .setString (4 , cls );
237
+ st .setString (5 , date );
238
+ st .setString (6 , sec );
239
+ st .setString (7 , tch );
240
+ st .setString (8 , rl );
241
+ st .setString (9 , "UEMK" );
242
+
243
+ int j =0 ;
244
+ j =st .executeUpdate ();
245
+
246
+ }
247
+ catch (Exception w1 )
248
+ {
249
+ System .out .println (w1 );
250
+ }
251
+
252
+ /**
253
+ *
254
+ * @author Soumyadip Chowdhury
255
+ * @github soumyadip007
256
+ *
257
+ */
258
+ if (i ==1 )
259
+ {
260
+ String n ="\n " ;
261
+
262
+
263
+ JOptionPane .showMessageDialog (btnNewButton ,"Congratulations," +n +"Student is added sucessfully" +n +"Thankyou." );
264
+ }
265
+ else
266
+ {
267
+
268
+ JOptionPane .showMessageDialog (btnNewButton ,"Please,enter the informations" );
269
+ }
270
+ }
271
+
272
+ }
273
+ });
274
+ btnNewButton .setFont (new Font ("Segoe UI" , Font .PLAIN , 30 ));
275
+ btnNewButton .setBounds (376 , 318 , 197 , 80 );
276
+ contentPane .add (btnNewButton );
277
+ /**
278
+ *
279
+ * @author Soumyadip Chowdhury
280
+ * @github soumyadip007
281
+ *
282
+ */
283
+ }
284
+ }
0 commit comments