-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteLibrarian.java
More file actions
166 lines (146 loc) · 4.15 KB
/
DeleteLibrarian.java
File metadata and controls
166 lines (146 loc) · 4.15 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
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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class DeleteLibrarian 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);}
}
DeleteLibrarian()
{
super("Delete Librarian");
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 Librarian"));
panel.setLayout(null);
contentPane.add(panel);
textField.setBounds(170, 35, 100, 26);
panel.add(textField);
textField.setColumns(10);
JLabel lblNewLabel = new JLabel("Librarian ID :");
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 account with this ID", "Delete Librarian",dialogButton);
if(dialogResult == JOptionPane.YES_OPTION)
{
try
{
pst=con.prepareStatement("delete from lib_registration1 where Lib_id=?");
pst.setString(1,textField.getText());
int m=pst.executeUpdate();
if(m==1)
{
JOptionPane.showMessageDialog(null,"Data Deleted Successfully");
}
else
{
JOptionPane.showMessageDialog(null, "Sorry! Account with this ID 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 DeleteLibrarian();
}
}