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 ("Job Role" );
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 ("Shift" );
76
+ lblGender .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
77
+ lblGender .setBounds (59 , 184 , 145 , 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 ("Day" );
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 ("Night" );
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 ("DD/MM/YYYY" );
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
+ JComboBox year = new JComboBox ();
135
+ for (int i =1901 ;i <=2018 ;i ++)
136
+ {
137
+ String str =String .valueOf (i );
138
+ year .addItem (str );
139
+ }
140
+ year .setBounds (841 , 32 , 109 , 27 );
141
+ contentPane .add (year );
142
+
143
+ JLabel lblRollNo = new JLabel ("Employee ID" );
144
+ lblRollNo .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
145
+ lblRollNo .setBounds (481 , 184 , 158 , 32 );
146
+ contentPane .add (lblRollNo );
147
+
148
+ JLabel lblClassTeacher = new JLabel ("Manager" );
149
+ lblClassTeacher .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
150
+ lblClassTeacher .setBounds (481 , 261 , 145 , 32 );
151
+ contentPane .add (lblClassTeacher );
152
+
153
+ JTextArea roll = new JTextArea ();
154
+ roll .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
155
+ roll .setBounds (662 , 185 , 166 , 37 );
156
+ contentPane .add (roll );
157
+
158
+ JLabel lblSection = new JLabel ("Duration" );
159
+ lblSection .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
160
+ lblSection .setBounds (481 , 107 , 169 , 32 );
161
+ contentPane .add (lblSection );
162
+
163
+ JTextArea teacher = new JTextArea ();
164
+ teacher .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
165
+ teacher .setBounds (662 , 262 , 166 , 37 );
166
+ contentPane .add (teacher );
167
+
168
+ JLabel lblClass = new JLabel ("Time" );
169
+ lblClass .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
170
+ lblClass .setBounds (59 , 261 , 145 , 32 );
171
+ contentPane .add (lblClass );
172
+
173
+ JTextArea stuclass = new JTextArea ();
174
+ stuclass .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
175
+ stuclass .setBounds (235 , 262 , 166 , 37 );
176
+ contentPane .add (stuclass );
177
+
178
+ JTextArea section = new JTextArea ();
179
+ section .setFont (new Font ("Segoe UI" , Font .PLAIN , 20 ));
180
+ section .setBounds (662 , 110 , 166 , 37 );
181
+ contentPane .add (section );
182
+
183
+ JButton btnNewButton = new JButton ("Add" );
184
+ btnNewButton .addActionListener (new ActionListener () {
185
+ /* (non-Javadoc)
186
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
187
+ */
188
+ public void actionPerformed (ActionEvent e ) {
189
+ int a =JOptionPane .showConfirmDialog (btnNewButton ,"Are you sure?" );
190
+ //JOptionPane.setRootFrame(null);
191
+ if (a ==JOptionPane .YES_OPTION ){
192
+
193
+ String name =stuname .getText ();
194
+ String prnt = partname .getText ();
195
+
196
+ String condition ="" ;
197
+ if (rdbtnNewRadioButton .isSelected ())
198
+ {
199
+ condition ="Male" ;
200
+
201
+ }
202
+ else if (rdbtnNewRadioButton_1 .isSelected ())
203
+ {
204
+ condition ="Female" ;
205
+
206
+ }
207
+ int i =1 ;
208
+ String cls =stuclass .getText ();
209
+ String rl =roll .getText ();
210
+ String tch =teacher .getText ();
211
+ String sec =section .getText ();
212
+
213
+
214
+ String dt =(String ) date .getSelectedItem ();
215
+ String mnth =(String ) month .getSelectedItem ();
216
+ String yr =(String ) year .getSelectedItem ();
217
+
218
+ String date =dt +"/" +mnth +"/" +yr ;
219
+ try {
220
+ System .out .println ("add" );
221
+
222
+ Class .forName ("com.mysql.jdbc.Driver" );
223
+
224
+ Connection con =(Connection ) DriverManager .getConnection ("jdbc:mysql://localhost:3306/school" ,"root" ,"" );
225
+
226
+ PreparedStatement st =(PreparedStatement ) con .prepareStatement ("INSERT INTO stu(name,prt,gender,class,dob,section,teach,roll,pass) values(?,?,?,?,?,?,?,?,?)" );
227
+
228
+ st .setString (1 , name );
229
+ st .setString (2 , prnt );
230
+ st .setString (3 , condition );
231
+ st .setString (4 , cls );
232
+ st .setString (5 , date );
233
+ st .setString (6 , sec );
234
+ st .setString (7 , tch );
235
+ st .setString (8 , rl );
236
+ st .setString (9 , "UEMK" );
237
+
238
+ int j =0 ;
239
+ j =st .executeUpdate ();
240
+
241
+ }
242
+ catch (Exception w1 )
243
+ {
244
+ System .out .println (w1 );
245
+ }
246
+
247
+
248
+ if (i ==1 )
249
+ {
250
+ String n ="\n " ;
251
+
252
+
253
+ JOptionPane .showMessageDialog (btnNewButton ,"Congratulations," +n +"Student is added sucessfully" +n +"Thankyou." );
254
+ }
255
+ else
256
+ {
257
+
258
+ JOptionPane .showMessageDialog (btnNewButton ,"Please,enter the informations" );
259
+ }
260
+ }
261
+
262
+ }
263
+ });
264
+ btnNewButton .setFont (new Font ("Segoe UI" , Font .PLAIN , 30 ));
265
+ btnNewButton .setBounds (376 , 318 , 197 , 80 );
266
+ contentPane .add (btnNewButton );
267
+
268
+ }
269
+ }
0 commit comments