-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPro.java
More file actions
487 lines (385 loc) · 12.9 KB
/
Pro.java
File metadata and controls
487 lines (385 loc) · 12.9 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class Pro implements ActionListener, ItemListener
{
JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10;
JFrame f1,f2,f3,f4,f5,f6,f7,f8;
JPanel p1,p2,p3,p4,p5;
JLabel lb1,lb2,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15;
JTextField t0,t1,ps,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12;
JTextArea tr1;
ImageIcon bimg1,bimg2;
Choice ch1,ch2,ch3;
Color c1;
String branch,semester,section;
JTable tb;
JScrollPane sp;
DefaultTableModel dtm;
public Pro()
{
//*******First Interface************
f1=new JFrame("Library Management System");
// p3 = new JPanel();
bimg1=new ImageIcon("i1.jpg");
// p3.setBackground(Color.MAGENTA);
//p3.setSize(500,500);
c1=new Color(31,190,214);
lb1=new JLabel(bimg1);
t0=new JTextField(8);
ps=new JPasswordField(8);
// lb1.setSize(400,400);
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f1.setVisible(true);
f1.setLayout(new BorderLayout());
f1.setLayout(new FlowLayout());
b1=new JButton("LogIn");
b1.setBackground(c1);
b1.setForeground(Color.white);
b1.addActionListener(this);
// p3.add(b1);
f1.add(b1);
f1.add(lb1);
// lb1.add(b1);
f1.setSize(2000,2000);
//*******Second Interface************
f2=new JFrame("Options");
bimg2=new ImageIcon("bgimg.png");
f2.setBackground(Color.MAGENTA);
f2.setBackground(Color.DARK_GRAY);
lb2=new JLabel(bimg2);
b2=new JButton("Issue book");
b2.setBounds(600,50,150,80);
b2.setBackground(c1);
b2.setForeground(Color.white);
b2.addActionListener(this);
b3=new JButton("Return book");
b3.setBackground(c1);
b3.setForeground(Color.white);
b3.setBounds(600,200,150,80);
b3.addActionListener(this);
b4=new JButton("All books");
b4.setBackground(c1);
b4.setForeground(Color.white);
b4.setBounds(600,350,150,80);
b4.addActionListener(this);
b5=new JButton("Insert Books");
b5.setBackground(c1);
b5.setForeground(Color.white);
b5.setBounds(600,500,150,80);
b5.addActionListener(this);
// b6=new JButton("Create new Admin");
// b6.setBackground(c1);
// b6.setForeground(Color.white);
// b6.setBounds(600,400,150,80);
// b6.addActionListener(this);
lb2.add(b2);
lb2.add(b3);
lb2.add(b4);
lb2.add(b5);
f2.add(lb2);
f2.setSize(2000,2000);
f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//*********Issuing Frame*************
f3=new JFrame("Issuing frame");
// f3.setLayout(new GridLayout(7,2));
p1=new JPanel();
p1.setBackground(Color.LIGHT_GRAY);
p2=new JPanel();
p2.setBackground(Color.LIGHT_GRAY);
l1=new JLabel("Student Name");
l2=new JLabel("Enrollment Number");
l3=new JLabel("Branch");
l4=new JLabel("Section");
l5=new JLabel("Semester");
l6=new JLabel("Book number");
l7=new JLabel("Book Name");
t1=new JTextField(8);
t2=new JTextField(8);
t3=new JTextField(8);
t4=new JTextField(8);
ch1=new Choice();
ch2=new Choice();
ch3=new Choice();
ch1.add("CSE");
ch1.add("ME");
ch1.add("CE");
ch1.add("EE");
ch1.add("EX");
ch1.add("AI&DS");
ch1.add("Pharma");
ch1.add("MBA");
ch2.add("1");
ch2.add("2");
ch2.add("3");
ch2.add("4");
ch2.add("5");
ch3.add("1");
ch3.add("2");
ch3.add("3");
ch3.add("4");
ch3.add("5");
ch3.add("6");
ch3.add("7");
ch3.add("8");
ch1.addItemListener(this);
ch2.addItemListener(this);
ch3.addItemListener(this);
p1.setLayout(new GridLayout(7,2));
p1.add(l1);
p1.add(t1);
p1.add(l2);
p1.add(t2);
p1.add(l3);
p1.add(ch1);
p1.add(l4);
p1.add(ch2);
p1.add(l5);
p1.add(ch3);
p1.add(l6);
p1.add(t3);
p1.add(l7);
p1.add(t4);
b7=new JButton("Insert");
b7.addActionListener(this);
b7.setBounds(500,100,30,30);
p2.add(b7);
f3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f3.setLayout(new GridLayout(2,1));
f3.add(p1);
f3.add(p2);
f3.setSize(2000,2000);
//**********************************RETURNING FRAME**************************************
f5 = new JFrame("Returning Books");
f5.setLayout(new GridLayout(2,2));
l9 = new JLabel("Enter book number");
t6 = new JTextField(8);
b8 = new JButton("Return");
b8.addActionListener(this);
f5.add(l9);
f5.add(t6);
f5.add(b8);
f5.setSize(300,300);
f5.setVisible(false);
//*******************ALL BOOKS FRAME************************
f6 = new JFrame("ALL AVAILABLE BOOKS");
dtm = new DefaultTableModel();
tb = new JTable(dtm);
sp = new JScrollPane(tb);
dtm.addColumn("Book Name");
dtm.addColumn("Book No.");
dtm.addColumn("Semester");
dtm.addColumn("Branch");
f6.add(sp);
f6.setSize(2000,2000);
f6.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//*************************INSERTING BOOK FRAME**************************
f7 = new JFrame("Inserting Books");
l10 = new JLabel("Book name");
t9 = new JTextField(20);
l11 = new JLabel("Book number");
t10 = new JTextField(10);
l12 = new JLabel("For Branch");
t11 = new JTextField(8);
l13 = new JLabel("For semester");
t12 = new JTextField(10);
b9 = new JButton("Insert");
b9.addActionListener(this);
f7.setLayout(new GridLayout(2,1));
p4 = new JPanel();
p4.setLayout(new GridLayout(4,2));
p5 = new JPanel();
p4.add(l10);
p4.add(t9);
p4.add(l11);
p4.add(t10);
p4.add(l12);
p4.add(t11);
p4.add(l13);
p4.add(t12);
p5.add(b9);
f7.add(p4);
f7.add(p5);
f7.setSize(2000,2000);
f7.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}//constructor close
//***********BUTTON Functions********
public void actionPerformed(ActionEvent act){
//************************************LogIn Button****************************
if(act.getSource()==b1){
Object[] message = {
"Username:", t0,
"Password:", ps
};
int option = JOptionPane.showConfirmDialog(null, message, "Login", JOptionPane.OK_CANCEL_OPTION);
if (option == JOptionPane.OK_OPTION) {
if (t0.getText().equals("h") && ps.getText().equals("h")) {
JOptionPane.showMessageDialog(lb1,"Login successful");
f2.setVisible(true);
}
else {
JOptionPane.showMessageDialog(lb1,"login failed");
}
}
else {
JOptionPane.showMessageDialog(lb1,"Login cancelled");
}
}
//**********Issue button*************
if(act.getSource()==b2){
//issue visible
f3.setVisible(true);
}
//***********************************************************
if(act.getSource()==b3){
//return visible
f5.setVisible(true);
}
/////////////////////////ALL BOOKS FRAME DETAILS BUTTONS/////////////////////////
if (act.getSource() == b4){
f6.setVisible(true);
String bn,bno,b,sem;
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e) {
System.out.println("Class not found "+ e);
}
try {
Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/bhumigupta","root","rootwdp");
PreparedStatement pst6 = con.prepareStatement("select * from allbook");
ResultSet rs = pst6.executeQuery();
while (rs.next()){
bn = rs.getString(1);
bno = rs.getString(2);
b = rs.getString(3);
sem = rs.getString(4);
dtm.addRow(new Object[]{bn,bno,b,sem});
}
}
catch(Exception e){
JOptionPane.showMessageDialog(f6,e.getMessage());
}
}
//*****??????***********INSERTING NEW BOOKS*******????????*************
if(act.getSource()==b5){
//NEW BOOK FRAME VISIBLE
f7.setVisible(true);
}
//(((((((((((((((((((((((ISSUE BOOK BUTTON)))))))))))))))))))))))
if(act.getSource()==b7) {
String s1="", s2 = "", s3 = "",s4 ="",s5="",s6="",s7="";
s1=t1.getText();
s2=t2.getText();
s3=ch1.getSelectedItem();
s4 = ch2.getSelectedItem();
s5 = ch3.getSelectedItem();
s6 = t3.getText();
s7 = t4.getText();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bhumigupta","root","rootwdp");
PreparedStatement pst = con.prepareStatement("INSERT INTO book values(?,?,?,?,?,?,?)");
pst.setString(1,s1);
pst.setString(2,s2);
pst.setString(3,s3);
pst.setString(4,s4);
pst.setString(5,s5);
pst.setString(6,s6);
pst.setString(7,s7);
int sm = pst.executeUpdate();
if(sm!=0)
JOptionPane.showMessageDialog(f3,"Issued");
else {
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
JOptionPane.showMessageDialog(f3,"Error");
con.close();
}
}
catch(Exception e){
JOptionPane.showMessageDialog(f3,e.getMessage());
//System.out.println();
}
}
//{{{{{{{{{{{{{{{{{{ RETURN BOOK BUTTON }}}}}}}}}}}}}}}}}}
if(act.getSource()==b8) {
String s1 = t6.getText();
// String s2 = t7.getText();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bhumigupta","root","rootwdp");
PreparedStatement pst2 = con.prepareStatement("delete from book where bookNum = ?");
pst2.setString(1,s1);
// pst2.setString(2,s2);
int en = pst2.executeUpdate();
if(en!=0)
JOptionPane.showMessageDialog(f5,"Returned");
else
{
JOptionPane.showMessageDialog(f5,"No such record");
con.close();
}
}
catch(Exception e){
JOptionPane.showMessageDialog(f5,"Alert:"+e.getMessage());
}
}
//???????????????????? INSERTING NEW BOOKS ?????????????????????/
if(act.getSource()==b9) {
String s1="", s2 = "", s3 = "",s4 ="";
s1=t9.getText();
s2=t10.getText();
s3=t11.getText();
s4 = t12.getText();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bhumigupta","root","rootwdp");
PreparedStatement pst = con.prepareStatement("INSERT INTO allbook values(?,?,?,?)");
pst.setString(1,s1);
pst.setString(2,s2);
pst.setString(3,s3);
pst.setString(4,s4);
int sm = pst.executeUpdate();
if(sm!=0)
JOptionPane.showMessageDialog(f7,"BOOK INSERTED");
else {
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
JOptionPane.showMessageDialog(f7,"Error");
con.close();
}
}
catch(Exception e){
JOptionPane.showMessageDialog(f7,e.getMessage());
}
}
}
//************Button function ends**********
//************Item Listener********
public void itemStateChanged(ItemEvent itm){
if(itm.getSource()==ch1){
branch=ch1.getSelectedItem();
}
if(itm.getSource()==ch2){
section=ch2.getSelectedItem();
}
if(itm.getSource()==ch3){
semester=ch3.getSelectedItem();
}
}
//************Item Listener ends***********
public static void main(String args[])
{
new Pro();
}
}