-
Notifications
You must be signed in to change notification settings - Fork 0
/
BookTakenTable1.java
315 lines (277 loc) · 7.96 KB
/
BookTakenTable1.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
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
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.table.*;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import java.sql.*;
import java.awt.event.*;
class BookTakenTable1 extends JFrame implements MouseListener
{
String head[]={"Book Title","Accession Number","Book Author","Book Publisher","Book Issued Date","Book Return Date"};
JTable tab=new JTable();
JScrollPane jsp=new JScrollPane(tab);
DefaultTableModel dtm;
int row,col=5;
int w,h;
Toolkit toolkit;
Dimension dim;
JPanel p=new JPanel();
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
JLabel l=new JLabel("You have not taken any book yet .");
JButton btnHome=new JButton("HOME");
JButton btnExit=new JButton("EXIT");
JButton btnPrint=new JButton("PRINT");
JButton btnAbout=new JButton("ABOUT");
JButton btnLogout=new JButton("LOGOUT");
JButton btnContact=new JButton("CONTACT");
JButton btnService=new JButton("SERVICES");
Connection con;
PreparedStatement ps;
static String data;
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("Jdbc:Odbc:mydsn","","");
dtm=new DefaultTableModel();
dtm.addColumn("Book Name");
dtm.addColumn("Book ID");
dtm.addColumn("Book Author");
dtm.addColumn("Book Publisher");
dtm.addColumn("Book Issued Date");
tab.setModel(dtm);
ps=con.prepareStatement("Select count(*) from bookTaken");
ResultSet rst=ps.executeQuery();
if(rst.next())
row=rst.getInt(1);
ps=con.prepareStatement("Select * from bookTaken");
rst=ps.executeQuery();
int r=0;
while(rst.next())
{
for(int j=0;j<col;j++)
tab.setValueAt(rst.getString(j+1),r,j);
r++;
}
}
catch(SQLException e){}
catch(ClassNotFoundException e){}
}
Color col1,col2;
BookTakenTable1()
{
super("BOOK TAKEN");
toolkit=Toolkit.getDefaultToolkit();
dim=toolkit.getScreenSize();
w=(int)dim.getWidth();
h=(int)dim.getHeight();
col1=btnHome.getForeground();
col2=btnPrint.getBackground();
// jsp.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, tab.getTableHeader());
add(p);
tab.setRowHeight(35);
tab.setPreferredScrollableViewportSize(new Dimension(1300,500));
tab.getTableHeader().setDefaultRenderer(new SimpleHeaderRenderer());
p.setLayout(null);
p3.setBackground(new Color(255,255,255));
p3.setPreferredSize(new Dimension(1450,70));
p3.setBounds(0,90,1450,70);
p.add(p3);
p3.setLayout(null);
l.setFont(new Font("Arial",Font.BOLD,20));
l.setBounds(560,10,400,30);
p3.add(l);
p2.setBackground(new Color(0,139,139));
p1.setPreferredSize(new Dimension(1450,90));
p1.setBounds(0,0,1450,90);
p.add(p1,"North");
p2.setPreferredSize(new Dimension(1350,460));
p2.setBounds(0,165,1350,460);
p.add(p2);
p1.setBackground(Color.lightGray);
p2.add(jsp);
p.add(p4,"South");
p4.setBounds(0,625,w,100);
p4.setPreferredSize(new Dimension(w,100));
p4.setBackground(new Color(0,139,139));
p4.setLayout(null);
//sort with 2 linestab.setAutoCreateRowSorter(true);
//to have sorted table tab.getRowSorter().toggleSortOrder(0);
JLabel la1 = new JLabel("Library ");
la1.setFont(new Font("Arial", Font.BOLD, 20));
la1.setForeground(Color.red);
la1.setBounds(25,8,100,30);
JLabel la2 = new JLabel("Management ");
la2.setFont(new Font("Arial", Font.BOLD, 18));
la2.setBounds(25,44,120,20);
JLabel la3 = new JLabel("System ");
la3.setFont(new Font("Arial", Font.BOLD, 18));
la3.setBounds(47,63,90,30);
p1.setLayout(null);
p1.add(la1);
p1.add(la2);
p1.add(la3);
setSize(w,h);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
btnHome.setForeground(Color.black);
btnHome.setBounds(560,30,100,25);
btnHome.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
btnHome.setBorderPainted(false);
btnHome.setContentAreaFilled(false);
btnHome.setFocusPainted(false);
Font btnFont =new Font("Arial", Font.PLAIN,18);
btnHome.setFont(btnFont);
p1.add(btnHome);
btnAbout.setForeground(Color.black);
btnAbout.setBounds(700,30,100,25);
btnAbout.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
btnAbout.setBorderPainted(false);
btnAbout.setContentAreaFilled(false);
btnAbout.setFocusPainted(false);
btnAbout.setFont(btnFont);
p1.add(btnAbout);
btnService.setForeground(Color.black);
btnService.setBounds(845,30,100,25);
btnService.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
btnService.setBorderPainted(false);
btnService.setContentAreaFilled(false);
btnService.setFocusPainted(false);
btnService.setFont(btnFont);
p1.add(btnService);
btnContact.setForeground(Color.black);
btnContact.setBounds(990,30,170,25);
btnContact.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
btnContact.setBorderPainted(false);
btnContact.setContentAreaFilled(false);
btnContact.setFocusPainted(false);
btnContact.setFont(btnFont);
p1.add(btnContact);
btnLogout.setForeground(Color.black);
btnLogout.setBounds(1200,30,100,25);
btnLogout.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
btnLogout.setBorderPainted(false);
btnLogout.setContentAreaFilled(false);
btnLogout.setFocusPainted(false);
btnLogout.setFont(btnFont);
p1.add(btnLogout);
btnPrint.setBounds(595,40,100,25);
p4.add(btnPrint);
btnPrint.setBackground(new Color(135,206,250));
btnPrint.setFocusPainted(false);
btnExit.setBounds(760,40,100,25);
p4.add(btnExit);
btnExit.setBackground(new Color(135,206,250));
btnExit.setFocusPainted(false);
btnHome.addMouseListener(this);
btnAbout.addMouseListener(this);
btnService.addMouseListener(this);
btnContact.addMouseListener(this);
btnLogout.addMouseListener(this);
btnPrint.addMouseListener(this);
btnExit.addMouseListener(this);
}
public void mouseClicked(MouseEvent e)
{
if(e.getSource()==btnPrint)
{
btnPrint.setBackground(Color.gray);
}
if(e.getSource()==btnExit)
{
btnExit.setBackground(Color.gray);
}
if(e.getSource()==btnHome)
{
this.dispose();
new HomePage().setVisible(true);
}
if(e.getSource()==btnLogout)
{
this.dispose();
new Logout().setVisible(true);
}
if(e.getSource()==btnService)
{
this.dispose();
new Service().setVisible(true);
}
if(e.getSource()==btnAbout)
{
this.dispose();
new About().setVisible(true);
}
if(e.getSource()==btnContact)
{
this.dispose();
new ContactUsPage().setVisible(true);
}
}
public void mousePressed(MouseEvent e)
{
if(e.getSource()==btnPrint)
{
btnPrint.setBackground(col2);
}
if(e.getSource()==btnExit)
{
btnExit.setBackground(col2);
}
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e)
{
if(e.getSource()==btnHome)
{
btnHome.setForeground(new Color(65,130,155));
}
if(e.getSource()==btnAbout)
{
btnAbout.setForeground(new Color(65,130,155));
}
if(e.getSource()==btnService)
{
btnService.setForeground(new Color(65,130,155));
}
if(e.getSource()==btnContact)
{
btnContact.setForeground(new Color(65,130,155));
}
if(e.getSource()==btnLogout)
{
btnLogout.setForeground(new Color(65,130,155));
}
}
public void mouseExited(MouseEvent e)
{
if(e.getSource()==btnHome)
{
btnHome.setForeground(col1);
}
if(e.getSource()==btnAbout)
{
btnAbout.setForeground(col1);
}
if(e.getSource()==btnService)
{
btnService.setForeground(col1);
}
if(e.getSource()==btnContact)
{
btnContact.setForeground(col1);
}
if(e.getSource()==btnLogout)
{
btnLogout.setForeground(col1);
}
}
public static void main(String []args)
{
new BookTakenTable1();
}
}