-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModifyFrame.java
109 lines (88 loc) · 2.01 KB
/
ModifyFrame.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
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.regex.*;
import mu.Sound;
public class ModifyFrame extends JFrame
{
JPanel jp1,jp2;
JButton modify,back;
JLabel l1,l2;
JTextField t1,t2;
public ModifyFrame()
{
super("Modify employee");
setSize(500,150);
setResizable(false);
jp1=new JPanel();
jp1.setLayout(new FlowLayout(FlowLayout.CENTER,10,25));
modify=new JButton("Update");
back=new JButton("Back");
l1=new JLabel("id:");
l2=new JLabel("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();
jp2.setLayout(new FlowLayout(FlowLayout.CENTER,10,25));
jp2.add(modify);
jp2.add(back);
add(jp2,BorderLayout.SOUTH);
setLocationRelativeTo(null);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
HomeFrame h=new HomeFrame();
dispose();
}
});
back.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
HomeFrame a=new HomeFrame();
dispose();
}
});
modify.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
String id=t1.getText();
String name=t2.getText();
if(id.length()==0)
{
Sound.failure();
JOptionPane.showMessageDialog(new JDialog(),"Id cannot be Empty");
return;
}
if(name.length()==0)
{
Sound.failure();
JOptionPane.showMessageDialog(new JDialog(),"Name cannot be Empty");
return;
}
if(!Pattern.matches("[0-9][0-9]*",id))
{
Sound.failure();
JOptionPane.showMessageDialog(new JDialog(),"Please Enter a valid Id");
return;
}
if(!Pattern.matches("[a-zA-Z][a-zA-Z]*",name))
{
Sound.failure();
JOptionPane.showMessageDialog(new JDialog(),"Please Enter a valid Name");
return;
}
DatabaseHandler q=new DatabaseHandler();
q.modify(Integer.parseInt(id),name);
t1.setText("");
t2.setText("");
}
});
}
}