-
Notifications
You must be signed in to change notification settings - Fork 1
/
Student.java
185 lines (155 loc) · 5.17 KB
/
Student.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
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
180
181
182
183
184
185
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JTree;
import javax.swing.JEditorPane;
import javax.swing.JCheckBoxMenuItem;
import java.awt.Choice;
import java.awt.TextField;
import java.awt.TextArea;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.Button;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.awt.event.ActionEvent;
public class Student extends Login {
protected JFrame frame3;
private JTextField textField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Student window = new Student();
window.frame3.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Student() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame3 = new JFrame();
frame3.setBounds(100, 100, 1200, 700);
frame3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame3.getContentPane().setLayout(null);
JLabel lblNewLabel = new JLabel("Student Window");
lblNewLabel.setBounds(12, 0, 226, 44);
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 24));
frame3.getContentPane().add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Course Initial");
lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 18));
lblNewLabel_1.setBounds(12, 169, 145, 16);
frame3.getContentPane().add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("");
lblNewLabel_2.setBounds(37, 228, 56, 16);
frame3.getContentPane().add(lblNewLabel_2);
JTextArea textArea = new JTextArea();
textArea.setBounds(356, 70, 517, 329);
frame3.getContentPane().add(textArea);
textField = new JTextField();
textField.setBounds(163, 109, 181, 22);
frame3.getContentPane().add(textField);
textField.setColumns(10);
textField.setText(globaluserid);
Choice choice = new Choice();
choice.setBounds(163, 169, 181, 22);
frame3.getContentPane().add(choice);
JButton btnNewButton = new JButton("Check Attendance");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// show the attendance.............................
textArea.setText("");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/student_attendance",
"root", "12345678");
String stid = textField.getText();
String crini = choice.getSelectedItem().toString();
String sql = "SELECT* FROM attendance WHERE Student_Id=('" + stid + "') AND Course_Initial=('"
+ crini + "');";
java.sql.PreparedStatement pst = con.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
textArea.append(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3) + " "
+ rs.getString(4) + " " + rs.getString(5) + " " + rs.getString(6) + "\n");
}
pst.close();
} catch (Exception e1) {
JOptionPane.showMessageDialog(null, e1);
}
}
});
btnNewButton.setBounds(105, 228, 145, 32);
frame3.getContentPane().add(btnNewButton);
Button button = new Button("Show");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// course initial according to studentid
int itemCount = choice.getItemCount();
for (int i = 0; i < itemCount; i++) {
choice.remove(0);
}
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/student_attendance",
"root", "12345678");
String str = textField.getText();
String sql = "SELECT DISTINCT Course_Initial FROM attendance WHERE Student_Id = ('" + str + "');";
java.sql.PreparedStatement pst = con.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
String name = rs.getString("Course_Initial");
choice.addItem(name);
}
pst.close();
} catch (Exception e1) {
JOptionPane.showMessageDialog(null, e1);
}
}
});
button.setBounds(266, 139, 72, 24);
frame3.getContentPane().add(button);
JLabel lblNewLabel_3 = new JLabel("Student Id");
lblNewLabel_3.setFont(new Font("Tahoma", Font.BOLD, 18));
lblNewLabel_3.setBounds(12, 112, 145, 16);
frame3.getContentPane().add(lblNewLabel_3);
JButton btnNewButton_1 = new JButton("Logout");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// logout for frame 3..........................................
frame3.dispose();
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Login window = new Login();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
});
btnNewButton_1.setBounds(37, 409, 109, 32);
frame3.getContentPane().add(btnNewButton_1);
}
}