-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusermenu.java
More file actions
92 lines (72 loc) · 4.02 KB
/
Copy pathusermenu.java
File metadata and controls
92 lines (72 loc) · 4.02 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
public static void user_menu(String UID) {
JFrame f=new JFrame("User Functions"); //Give dialog box name as User functions
//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Exit user menu on closing the dialog box
JButton view_but=new JButton("View Books");//creating instance of JButton
view_but.setBounds(20,20,120,25);//x axis, y axis, width, height
view_but.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
JFrame f = new JFrame("Books Available"); //View books stored in database
//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Connection connection = connect();
String sql="select * from BOOKS"; //Retreive data from database
try {
Statement stmt = connection.createStatement(); //connect to database
stmt.executeUpdate("USE LIBRARY"); // use librabry
stmt=connection.createStatement();
ResultSet rs=stmt.executeQuery(sql);
JTable book_list= new JTable(); //show data in table format
book_list.setModel(DbUtils.resultSetToTableModel(rs));
JScrollPane scrollPane = new JScrollPane(book_list); //enable scroll bar
f.add(scrollPane); //add scroll bar
f.setSize(800, 400); //set dimensions of view books frame
f.setVisible(true);
f.setLocationRelativeTo(null);
} catch (SQLException e1) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null, e1);
}
}
}
);
JButton my_book=new JButton("My Books");//creating instance of JButton
my_book.setBounds(150,20,120,25);//x axis, y axis, width, height
my_book.addActionListener(new ActionListener() { //Perform action
public void actionPerformed(ActionEvent e){
JFrame f = new JFrame("My Books"); //View books issued by user
//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
int UID_int = Integer.parseInt(UID); //Pass user ID
//.iid,issued.uid,issued.bid,issued.issued_date,issued.return_date,issued,
Connection connection = connect(); //connect to database
//retrieve data
String sql="select distinct issued.*,books.bname,books.genre,books.price from issued,books " + "where ((issued.uid=" + UID_int + ") and (books.bid in (select bid from issued where issued.uid="+UID_int+"))) group by iid";
String sql1 = "select bid from issued where uid="+UID_int;
try {
Statement stmt = connection.createStatement();
//use database
stmt.executeUpdate("USE LIBRARY");
stmt=connection.createStatement();
//store in array
ArrayList books_list = new ArrayList();
ResultSet rs=stmt.executeQuery(sql);
JTable book_list= new JTable(); //store data in table format
book_list.setModel(DbUtils.resultSetToTableModel(rs));
//enable scroll bar
JScrollPane scrollPane = new JScrollPane(book_list);
f.add(scrollPane); //add scroll bar
f.setSize(800, 400); //set dimensions of my books frame
f.setVisible(true);
f.setLocationRelativeTo(null);
} catch (SQLException e1) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null, e1);
}
}
}
);
f.add(my_book); //add my books
f.add(view_but); // add view books
f.setSize(300,100);//400 width and 500 height
f.setLayout(null);//using no layout managers
f.setVisible(true);//making the frame visible
f.setLocationRelativeTo(null);
}