-
Notifications
You must be signed in to change notification settings - Fork 0
/
BookDetails.java
211 lines (178 loc) · 6.54 KB
/
BookDetails.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
package library1;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import net.proteanit.sql.DbUtils;
import java.sql.*;
import java.awt.event.*;
public class BookDetails extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTable table;
private JTextField search;
private static JButton b1, b2, b3;
public static void main(String[] args) {
new BookDetails().setVisible(true);
}
public void Book() {
try {
conn con = new conn();
String sql = "select * from book";
PreparedStatement st = con.c.prepareStatement(sql);
ResultSet rs = st.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
rs.close();
st.close();
con.c.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "hey select * from book");
}
}
public BookDetails() {
setBounds(350, 200, 890, 475);
contentPane = new JPanel();
contentPane.setBackground(Color.WHITE);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(79, 133, 771, 282);
contentPane.add(scrollPane);
table = new JTable();///////////////////////// table
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
int row = table.getSelectedRow();
search.setText(table.getModel().getValueAt(row, 0).toString());
}
});
table.setBackground(new Color(240, 248, 255));
table.setForeground(Color.DARK_GRAY);
table.setFont(new Font("Trebuchet MS", Font.BOLD, 16));
scrollPane.setViewportView(table);
//---------------------------search button------------------------------------------------------
JButton b1 = new JButton("Search");
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
conn con = new conn();
if (ae.getSource() == b1) {
// System.out.println("heeeyyy you clicked search");
// String sql = "select * from book where concat(name, book_id) like '"+search.getText()+"'";
// ResultSet rs = con.s.executeQuery(sql);
// table.setModel(DbUtils.resultSetToTableModel(rs));
// rs.close();
String sql = "select * from book where concat(name, book_id) like ?";
PreparedStatement st = con.c.prepareStatement(sql);
st.setString(1, "%" + search.getText() + "%");
ResultSet rs = st.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
rs.close();
st.close();
}
} catch (Exception e2) {
// TODO: handle exception
}
}
});
b1.setBorder(new LineBorder(new Color(255, 20, 147), 2, true));
ImageIcon i1 = new ImageIcon("D:/java new 1/library1/book5.png");
Image i2 = i1.getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT);
ImageIcon i3 = new ImageIcon(i2);
b1.setIcon(i3);
b1.setForeground(new Color(199, 21, 133));
b1.setFont(new Font("Trebuchet MS", Font.BOLD, 18));
b1.setBounds(564, 89, 138, 33);
contentPane.add(b1);
//-------------------------delete button--------------------------------------------------
JButton b2 = new JButton("Delete");
b2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
// TODO Auto-generated method stub
conn con = new conn();
try {
if (ae.getSource() == b2) {
// System.out.println("clicked");
//--------yesma deutai sql if ma gayo---------------------------
// String sql = "delete from book where name ='" + search.getText() + "'";
// int rs = con.s.executeUpdate(sql);
String sql = "delete from book where book_id ='" + search.getText() + "'";
int rs = con.s.executeUpdate(sql);
if (rs == 1) {
JOptionPane.showMessageDialog(null, "done!!");
setVisible(false);
} else {
JOptionPane.showMessageDialog(null, "Please Write Book_Id to del!!");
}
//
// if (rs2 == 1) {
// JOptionPane.showMessageDialog(null, "done!! book deleted ");
// setVisible(false);
//
// } else {
// JOptionPane.showMessageDialog(null, "Something is not !!");
// }
}
} catch (Exception e2) {
// TODO: handle exception
}
setVisible(true);
}
});
ImageIcon i4 = new ImageIcon("D:/java new 1/library1/book5.png");
Image i5 = i4.getImage().getScaledInstance(30, 30, Image.SCALE_DEFAULT);
ImageIcon i6 = new ImageIcon(i5);
b2.setIcon(i6);
b2.setForeground(new Color(199, 21, 133));
b2.setFont(new Font("Trebuchet MS", Font.BOLD, 18));
b2.setBorder(new LineBorder(new Color(255, 20, 147), 2, true));
b2.setBounds(712, 89, 138, 33);
contentPane.add(b2);
//----------------------------------------------------------------------------------------------
JLabel l1 = new JLabel("Book Details");
l1.setForeground(new Color(107, 142, 35));
l1.setFont(new Font("Trebuchet MS", Font.BOLD | Font.ITALIC, 30));
l1.setBounds(300, 15, 400, 47);
contentPane.add(l1);
search = new JTextField();
search.setBackground(new Color(255, 240, 245));
search.setBorder(new LineBorder(new Color(255, 105, 180), 2, true));
search.setForeground(new Color(47, 79, 79));
search.setFont(new Font("Trebuchet MS", Font.BOLD | Font.ITALIC, 17));
search.setBounds(189, 89, 357, 33);
search.setColumns(10);
contentPane.add(search);
JLabel l3 = new JLabel("Back");
l3.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
setVisible(false);
home home = new home();
home.setVisible(true);
}
});
l3.setForeground(Color.GRAY);
l3.setFont(new Font("Trebuchet MS", Font.BOLD, 18));
ImageIcon i7 = new ImageIcon("D:/java new 1/library1/book5.png");
Image i8 = i7.getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT);
ImageIcon i9 = new ImageIcon(i8);
l3.setIcon(i9);
l3.setBounds(97, 89, 72, 33);
contentPane.add(l3);
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(new LineBorder(new Color(0, 128, 128), 3, true), "Book-Details",
TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 128, 0)));
panel.setBounds(67, 54, 793, 368);
contentPane.add(panel);
panel.setBackground(Color.WHITE);
Book();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}