-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentDetails.java
More file actions
179 lines (152 loc) · 5.43 KB
/
StudentDetails.java
File metadata and controls
179 lines (152 loc) · 5.43 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package library1;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.border.*;
import net.proteanit.sql.DbUtils;
public class StudentDetails extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTable table;
private JTextField search;
private JButton b1, b2;
public static void main(String[] args) {
new StudentDetails().setVisible(true);
}
public void student() {
try {
conn con = new conn();
String sql = "select * from student";
PreparedStatement st = con.c.prepareStatement(sql);
ResultSet rs = st.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
rs.close();
st.close();
con.c.close();
} catch (Exception e) {
}
}
public StudentDetails() {
setBounds(350, 200, 890, 475);
contentPane = new JPanel();
contentPane.setBackground(new Color(220, 220, 220));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setBackground(Color.WHITE);
contentPane.setLayout(null);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(79, 133, 771, 288);
contentPane.add(scrollPane);
table = new JTable();
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
int row = table.getSelectedRow();
search.setText(table.getModel().getValueAt(row, 0).toString());
}
});
table.setBackground(new Color(240, 248, 255));
table.setForeground(Color.DARK_GRAY);
table.setFont(new Font("Trebuchet MS", Font.BOLD, 16));
scrollPane.setViewportView(table);
b1 = new JButton("Search");
b1.addActionListener(this);
b1.setBorder(new LineBorder(new Color(255, 20, 147), 2, true));
ImageIcon i1 = new ImageIcon("D:/java new 1/library1/book5.png");
Image i2 = i1.getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT);
ImageIcon i3 = new ImageIcon(i2);
b1.setIcon(i3);
b1.setForeground(new Color(199, 21, 133));
b1.setFont(new Font("Trebuchet MS", Font.BOLD, 18));
b1.setBounds(564, 89, 138, 33);
contentPane.add(b1);
b2 = new JButton("Delete");
b2.addActionListener(this);
ImageIcon i4 = new ImageIcon("D:/java new 1/library1/book5.png");
Image i5 = i4.getImage().getScaledInstance(30, 30, Image.SCALE_DEFAULT);
ImageIcon i6 = new ImageIcon(i5);
b2.setIcon(i6);
b2.setForeground(new Color(199, 21, 133));
b2.setFont(new Font("Trebuchet MS", Font.BOLD, 18));
b2.setBorder(new LineBorder(new Color(255, 20, 147), 2, true));
b2.setBounds(712, 89, 138, 33);
contentPane.add(b2);
JLabel l1 = new JLabel("Student Details");
l1.setForeground(new Color(102, 205, 170));
l1.setFont(new Font("Trebuchet MS", Font.BOLD | Font.ITALIC, 26));
l1.setBounds(250, 20, 400, 47);
contentPane.add(l1);
search = new JTextField();
search.setBackground(new Color(255, 240, 245));
search.setBorder(new LineBorder(new Color(255, 105, 180), 2, true));
search.setForeground(new Color(47, 79, 79));
search.setFont(new Font("Trebuchet MS", Font.BOLD | Font.ITALIC, 17));
search.setBounds(189, 89, 357, 33);
contentPane.add(search);
search.setColumns(10);
JLabel l2 = new JLabel("Back");
l2.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
setVisible(false);
home home = new home();
home.setVisible(true);
}
});
l2.setForeground(Color.GRAY);
l2.setFont(new Font("Trebuchet MS", Font.BOLD, 18));
ImageIcon i7 = new ImageIcon("D:/java new 1/library1/book5.png");
Image i8 = i7.getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT);
ImageIcon i9 = new ImageIcon(i8);
l2.setIcon(i9);
l2.setBounds(97, 89, 72, 33);
contentPane.add(l2);
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(new LineBorder(new Color(95, 158, 160), 3, true), "Student-Deatails",
TitledBorder.LEADING, TitledBorder.TOP, null, new Color(72, 209, 204)));
panel.setBounds(68, 59, 790, 370);
panel.setBackground(Color.WHITE);
contentPane.add(panel);
student();
}
public void actionPerformed(ActionEvent ae) {
try {
int response = 0;
conn con = new conn();
if (ae.getSource() == b1) {
String sql = "select * from student where concat(name, student_id) like ?";
PreparedStatement st = con.c.prepareStatement(sql);
st.setString(1, "%" + search.getText() + "%");
ResultSet rs = st.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
rs.close();
st.close();
}
if (ae.getSource() == b2) {
String sql = "delete from student where student_id = '" + search.getText() + "'";
PreparedStatement st = con.c.prepareStatement(sql);
JDialog.setDefaultLookAndFeelDecorated(true);
response = JOptionPane.showConfirmDialog(null, "Do you want to continue?", "Confirm",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (response == JOptionPane.NO_OPTION) {
} else if (response == JOptionPane.YES_OPTION) {
int rs = st.executeUpdate();
if(rs == 1) {
JOptionPane.showMessageDialog(null, "Deleted !!");}
else {
JOptionPane.showMessageDialog(null, "Deleted !!");
}
}
} else if (response == JOptionPane.CLOSED_OPTION) {
}
// st.close();
// con.c.close();
}catch(
Exception e)
{
}
}}