-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUViewBook.java
210 lines (153 loc) · 3.98 KB
/
UViewBook.java
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
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
class UViewBook extends JFrame implements ActionListener
{
//Declaring Label , TextField , Panel , ScrollPane , etc......
JPanel p,ph,p1,ph1;
JButton b;
ImageIcon img;
JScrollPane s;
JTable t;
JTableHeader header;
String Data[][];
String Head[]={"Book_Id","Book_Name","Publisher_Name","Published_Year","Book_Price","Quantity","Pages","Category","Shelf_No."};
JLabel l1,lh,li;
Connection con;
ResultSet rs;
Statement smt;
public UViewBook()
{
//p=new JPanel();
this.setVisible(true);
this.setTitle("Books Record");
this.setSize(2000,2000);
// p.setLayout(null);
this.setResizable(true);
p=new JPanel();
p.setLayout(null);
p.setBounds(0,0,1500,800);
//p.setBackground(Color.WHITE);
p.setBackground(new Color(200,200,200));
this.add(p);
ph=new JPanel();
ph.setLayout(null);
ph.setBounds(0,60,1500,50);
ph.setBackground(new Color(221,221,221));
p.add(ph);
Font f=new Font("ArialBlack",Font.BOLD,32);
Font f1=new Font("ArialBlack",Font.BOLD,20);
Font f2=new Font("ArialBlack",Font.BOLD,15);
lh=new JLabel("LIBRARY MANAGEMENT SYSTEM");
lh.setBounds(430,10,800,30);
lh.setForeground(Color.BLACK);
lh.setFont(f);
ph.add(lh);
ph1=new JPanel();
ph1.setLayout(null);
ph1.setBounds(0,130,180,40);
ph1.setBackground(Color.BLACK);
// ph1.setBackground(new Color(221,221,221));
p.add(ph1);
/*img=new ImageIcon("img1.jpg");
li=new JLabel(img);
li.setBounds(0,7,20,20);
ph1.add(li);*/
l1=new JLabel("LIBRARY BOOKS");
l1.setBounds(10,5,180,30);
l1.setForeground(Color.WHITE);
l1.setFont(f1);
ph1.add(l1);
b=new JButton("BACK");
b.setBounds(1200,130,100,40);
b.setBackground(Color.BLACK);
b.setForeground(Color.WHITE);
b.setFont(f2);
p.add(b);
//panel
p1=new JPanel();
//p1.setBounds(30,150,1300,420);
p1.setBounds(80,200,1200,400);
p1.setBackground(new Color(221,221,221));
p1.setLayout(new BorderLayout(20,20));
p.add(p1);
b.addActionListener(this);
getTable();
}
public void getTable()
{
try
{
//for connect into database
Class.forName("com.mysql.cj.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/library","root","mysqlpasswd@25");
//query
smt=con.createStatement();
rs=smt.executeQuery("select * from books_detail");
//count record
int r=0;
while(rs.next())
{
r++;
}
rs=smt.executeQuery("select * from books_detail");
Data = new String[r][9];
int j,i;
i=j=0;
while(rs.next())
{
Data[i][j]=rs.getString(1);
j++;
Data[i][j]=rs.getString(2);
j++;
Data[i][j]=rs.getString(3);
j++;
Data[i][j]=rs.getString(4);
j++;
Data[i][j]=rs.getString(5);
j++;
Data[i][j]=rs.getString(6);
j++;
Data[i][j]=rs.getString(7);
j++;
Data[i][j]=rs.getString(8);
j++;
Data[i][j]=rs.getString(9);
j++;
i++;
j=0;
}
//table declearation and table header
t=new JTable(Data,Head);
t.setBounds(20,20,1200,300);
//t.setBackground(new Color(221,221,221));
p1.add(t);
s=new JScrollPane(t);
s.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
//s.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
p1.add(s);
header= t.getTableHeader();
header.setBackground(new Color(211,211,211));
header.setFont(new Font ("Arial",Font.BOLD,16));
}catch(Exception e)
{
System.out.println(e);
}
}
public void actionPerformed(ActionEvent ae)
{
Object o = ae.getSource();
if(o==b)
{
new UserPage();
this.dispose();
}
}
public static void main(String ar[])
{
new UViewBook();
}
}