-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeleteBook.java
169 lines (146 loc) · 4.13 KB
/
DeleteBook.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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class DeleteBook extends JFrame implements MouseListener, ActionListener, FocusListener
{
JPanel contentPane,panel;
Color col;
JTextField textField = new JTextField();
JButton btnDel = new JButton("Delete");
JButton btnReset = new JButton("Reset");
JButton btnCancel = new JButton("Cancel");
Connection con;
PreparedStatement pst;
ResultSet rst;
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("Jdbc:Odbc:mydsn","","");
}
catch(SQLException e){JOptionPane.showMessageDialog(null,e);}
catch(ClassNotFoundException e){JOptionPane.showMessageDialog(null,e);}
}
DeleteBook()
{
super("Delete Book");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);
setBounds(20, 20, 590, 450);
setLocationRelativeTo(null);
contentPane = new JPanel();
contentPane.setBackground(new Color(0, 139, 139));
// contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
panel = new JPanel();
panel.setBounds(72, 57, 450, 250);
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Delete Book"));
panel.setLayout(null);
contentPane.add(panel);
textField.setBounds(170, 35, 100, 26);
panel.add(textField);
textField.setColumns(10);
JLabel lblNewLabel = new JLabel("Accession Number :");
lblNewLabel.setBounds(6, 41, 115, 14);
panel.add(lblNewLabel);
btnDel.setBounds(71, 120, 89, 23);
panel.add(btnDel);
btnReset.setBounds(171, 120, 89, 23);
panel.add(btnReset);
btnCancel.setBounds(271, 120, 89, 23);
panel.add(btnCancel);
btnDel.setBackground(new Color(135,206,250));
btnReset.setBackground(new Color(135,206,250));
btnCancel.setBackground(new Color(135,206,250));
btnDel.addActionListener(this);
btnReset.addActionListener(this);
btnCancel.addActionListener(this);
btnDel.addMouseListener(this);
btnReset.addMouseListener(this);
btnCancel.addMouseListener(this);
textField.addFocusListener(this);
col=btnDel.getBackground();
}
public void focusGained(FocusEvent f)
{
if(f.getSource()==textField)
{
textField.setBackground(new Color(240,230,140));
}
}
public void focusLost(FocusEvent f){}
public void mouseEntered(MouseEvent m)
{}
public void mouseExited(MouseEvent m)
{
if(m.getSource()==btnDel)
{
btnDel.setBackground(col);
}
if(m.getSource()==btnReset)
{
btnReset.setBackground(col);
}
if(m.getSource()==btnCancel)
{
btnCancel.setBackground(col);
}
}
public void mouseClicked(MouseEvent m)
{
if(m.getSource()==btnDel)
{
btnDel.setBackground(Color.gray);
}
if(m.getSource()==btnReset)
{
btnReset.setBackground(Color.gray);
}
if(m.getSource()==btnCancel)
{
btnCancel.setBackground(Color.gray);
}
}
public void mousePressed(MouseEvent m){}
public void mouseReleased(MouseEvent m){}
public void actionPerformed(ActionEvent a)
{
if(a.getSource()==btnDel)
{
int dialogButton = JOptionPane.YES_NO_OPTION;
int dialogResult = JOptionPane.showConfirmDialog(null, "Are you sure to delete this Book", "Delete Book",dialogButton);
if(dialogResult == JOptionPane.YES_OPTION)
{
try
{
pst=con.prepareStatement("delete from book_info where accession=?");
pst.setString(1,textField.getText());
int m =pst.executeUpdate();
if(m==1)
{
JOptionPane.showMessageDialog(null,"Data Deleted Successfully");
}
else
{
JOptionPane.showMessageDialog(null, "Sorry! Book with this accession number doesnot exist! ");
}
}
catch(SQLException ee){JOptionPane.showMessageDialog(null,ee);}
}
}
if(a.getSource()==btnReset)
{
textField.setText(null);
}
if(a.getSource()==btnCancel)
{
this.dispose();
}
}
public static void main(String []args)
{
new DeleteBook();
}
}