-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModifyFrame.java
More file actions
114 lines (87 loc) · 2.56 KB
/
ModifyFrame.java
File metadata and controls
114 lines (87 loc) · 2.56 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
package app;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import app.*;
import mu.*;
public class ModifyFrame extends JFrame{
JPanel jp1,jp2;
JButton modify,close;
JLabel l1,l2;
JTextField t1,t2;
public ModifyFrame(){
super("Update Employee");
setSize(500,200);
setResizable(false);
jp1=new JPanel();
jp1.setLayout(new FlowLayout(FlowLayout.CENTER,10,25));
modify=new JButton("Update");
close=new JButton("Close");
l1=new JLabel("Employee Id:");
l2=new JLabel("Employee Name:");
t1=new JTextField(5);
t2=new JTextField(10);
jp1.add(l1);
jp1.add(t1);
jp1.add(l2);
jp1.add(t2);
add(jp1);
jp2=new JPanel(); //buttons for adding or closing the frame
jp2.setLayout(new FlowLayout(FlowLayout.CENTER,10,25));
jp2.add(modify);
jp2.add(close);
add(jp2,BorderLayout.SOUTH);
setLocationRelativeTo(null);
setVisible(true);
addWindowListener(new WindowAdapter(){ //event handling
public void windowClosing(WindowEvent we){
HomeFrame h = new HomeFrame();
dispose();
}
});
modify.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String id = t1.getText();
String name = t2.getText();
if((id.length()==0)||(name.length()==0))
{
Sound.failure();
JOptionPane.showMessageDialog(new JDialog(), "Please fill all the fields");
return;
}
try
{ //Validation
int a = Integer.parseInt(id);
char[] chars = name.toCharArray();
for (char c : chars) {
if(!Character.isLetter(c)) {
throw new Exception();
}
}
DatabaseHandler db = new DatabaseHandler();
db.modify(a,name);
t1.requestFocus();
}
catch(NumberFormatException nf)
{
Sound.failure();
JOptionPane.showMessageDialog(jp1,"Please enter a number in the Employee id field");
}
catch(Exception e)
{
Sound.failure();
JOptionPane.showMessageDialog(jp1,"Please enter alphabet only in the Employee name field");
}
t1.setText("");t2.setText("");
}
});
//Close Button
close.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
new HomeFrame();
dispose();
}
});
}
}