-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathStudentDetails.java
More file actions
147 lines (120 loc) · 3.83 KB
/
Copy pathStudentDetails.java
File metadata and controls
147 lines (120 loc) · 3.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
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
import com.mysql.cj.protocol.Resultset;
import javax.swing.*;
import javax.xml.transform.Result;
import java.awt.*;
import java.sql.*;
import net.proteanit.sql.DbUtils; // rs2xml
import java.awt.event.*;
public class StudentDetails extends JFrame implements ActionListener{
Choice crollno; //dropdown by choice method
JButton search,print,update,add,cancel;
JTable jtable;
StudentDetails(){
getContentPane().setBackground(Color.WHITE);
setLayout(null);
setSize(1000,700);
setLocation(250,20);
// search by roll number
JLabel heading = new JLabel("Search By Roll Number");
heading.setBounds(20,20,150,20);
add(heading);
crollno= new Choice();
crollno.setBounds(180,20,150,20);
add(crollno);
//take the roll number from Mysql
try {
Conn c = new Conn();
ResultSet rs = c.s.executeQuery("select * from student ");
while (rs.next()){
crollno.add(rs.getString("rollNumG"));
}
}catch (Exception e){
e.printStackTrace();
}
jtable = new JTable();
try {
Conn c = new Conn();
ResultSet rs = c.s.executeQuery("select * from student ");
jtable.setModel(DbUtils.resultSetToTableModel(rs)); // value insert in table
}catch (Exception e){
e.printStackTrace();
}
JScrollPane jsp = new JScrollPane(jtable); // for the scrollbar
jsp.setBounds(0,100,1000,700);
add(jsp);
// search button
search = new JButton("Search");
search.setBounds(20,70,100,20);
search.setBackground(Color.BLACK);
search.setForeground(Color.WHITE);
search.addActionListener(this::actionPerformed);
search.setFont(new Font("Tahoma",Font.BOLD,15));
add(search);
//print button
print = new JButton("Print");
print.setBounds(140,70,100,20);
print.setBackground(Color.BLACK);
print.setForeground(Color.WHITE);
print.addActionListener(this);
print.setFont(new Font("Tahoma",Font.BOLD,15));
add(print);
// add button
add = new JButton("Add");
add.setBounds(260,70,100,20);
add.setBackground(Color.BLACK);
add.setForeground(Color.WHITE);
add.addActionListener(this);
add.setFont(new Font("Tahoma",Font.BOLD,15));
add(add);
// update button
update = new JButton("Update");
update.setBounds(380,70,100,20);
update.setBackground(Color.BLACK);
update.setForeground(Color.WHITE);
update.addActionListener(this);
update.setFont(new Font("Tahoma",Font.BOLD,15));
add(update);
// cancel button
cancel = new JButton("Cancel");
cancel.setBounds(500,70,100,20);
cancel.setBackground(Color.BLACK);
cancel.setForeground(Color.WHITE);
cancel.addActionListener(this);
cancel.setFont(new Font("Tahoma",Font.BOLD,15));
add(cancel);
setVisible(true);
}
public void actionPerformed(ActionEvent ae){
if (ae.getSource()==cancel){
setVisible(false);
}
else if (ae.getSource()==search){
String query = "select * from student where rollNumG = '"+crollno.getSelectedItem()+"'";
try{
Conn c = new Conn();
ResultSet rs = c.s.executeQuery(query);
jtable.setModel(DbUtils.resultSetToTableModel(rs));
}catch (Exception e){
e.printStackTrace();
}
}
else if (ae.getSource()==print) {
try{
jtable.print();
}catch (Exception ee){
ee.printStackTrace();
}
}
else if (ae.getSource()==add){
setVisible(false);
new AddStudent();
}
else if (ae.getSource()==update) {
setVisible(false);
new UpdateStudents();
}
}
public static void main(String[] args) {
new StudentDetails();
}
}