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