-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddFrame.java
75 lines (66 loc) · 1.47 KB
/
AddFrame.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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class AddFrame extends JFrame{
Container c;
JLabel lblRno,lblName;
JTextField txtRno,txtName;
JButton btnSave,btnBack;
JPanel p1,p2;
AddFrame(){
c=getContentPane();
c.setLayout(new BoxLayout(c,BoxLayout.Y_AXIS));
p1=new JPanel();
lblRno=new JLabel("Rno:");
txtRno=new JTextField(4);
lblName=new JLabel("Name:");
txtName=new JTextField(10);
p1.add(lblRno);
p1.add(txtRno);
p1.add(lblName);
p1.add(txtName);
c.add(p1);
p2=new JPanel();
btnSave=new JButton("Save");
btnBack=new JButton("Back");
p2.add(btnSave);
p2.add(btnBack);
c.add(p2);
btnSave.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String rno2=txtRno.getText();
String name=txtName.getText();
try
{
int rno=Integer.parseInt(rno2);
if(name.matches("^[a-zA-Z\\s]*$")&&(rno>0))
{
DbHandler db=new DbHandler();
db.addStudent(rno,name);
}
else{
JOptionPane.showMessageDialog(new JDialog(),"Please Re-Enter The Values");
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(new JDialog(),"Records not Added");
}
txtRno.setText("");
txtRno.requestFocus();
txtName.setText("");
}
});
btnBack.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
MainFrame a=new MainFrame();
dispose();
}
});
setTitle("Add Student");
setSize(350,200);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}