-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStudent.java
More file actions
101 lines (86 loc) · 2.83 KB
/
Student.java
File metadata and controls
101 lines (86 loc) · 2.83 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
package GUI;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import Business.StudentDB;
public class Student {
JFrame f = new JFrame("Student");
JLabel lbId = new JLabel("ID");
JTextField tfId = new JTextField(10);
JLabel lbName = new JLabel("Name");
JTextField tfName = new JTextField(10);
JLabel lbMath = new JLabel("Math");
JTextField tfMath = new JTextField(10);
JButton btnInsert = new JButton("Insert");
JButton btnUpdate = new JButton("Update");
JButton btnDelete = new JButton("Delete");
JButton btnView = new JButton("View");
public Student() {
f.setLocation(300, 300);
f.setLayout(new GridLayout(5,2));
f.add(lbId);
f.add(tfId);
f.add(lbName);
f.add(tfName);
f.add(lbMath);
f.add(tfMath);
f.add(btnInsert);
btnInsert.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
StudentDB s = new StudentDB();
int record = s.ExcuteUpdate("Insert into Student values('"+tfId.getText()+"','"+tfName.getText()+"','"+tfMath.getText()+"')");
if(record>0) JOptionPane.showMessageDialog(null, "Add "+record+" rows");
} catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
}
} });
f.add(btnUpdate);
btnUpdate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
StudentDB s = new StudentDB();
int record = s.ExcuteUpdate("Update Student set Name ='"+tfName.getText()+"',Math ='"+tfMath.getText()+"' where Id = '"+tfId.getText()+"' ");
if(record>0) JOptionPane.showMessageDialog(null, "Update "+record+" rows");
} catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
}
} });
f.add(btnDelete);
btnDelete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
StudentDB s = new StudentDB();
int record = s.ExcuteUpdate("DELETE FROM Student WHERE Id = '"+tfId.getText()+"'");
if(record>0) JOptionPane.showMessageDialog(null, "Delete "+record+" rows");
} catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
}
} });
f.add(btnView);
btnView.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ViewStudent vs = new ViewStudent();
vs.setVisible(true);
} });
f.setSize(200 , 200);
f.pack();
f.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Student();
}
}