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