-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStdScore.java
More file actions
89 lines (76 loc) · 2.33 KB
/
StdScore.java
File metadata and controls
89 lines (76 loc) · 2.33 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
package KYUTES;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class StdScore implements ActionListener {
public JFrame frame;
private JPanel stdScore;
private JButton previous;
private static String userName;
/*public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
StdScore window = new StdScore(userName);
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}*/
public StdScore(String userName) {
this.userName = userName;
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setSize(900, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
BarPanel bar = new BarPanel(frame,userName);
stdScore = new JPanel();
stdScore.setBounds(0, 50, 900, 550);
stdScore.setBackground(new Color(186, 202, 224));
stdScore.setLayout(null);
frame.getContentPane().add(stdScore);
DefaultTableModel model = new DefaultTableModel();
JTable table = new JTable(model);
table.setBackground(new Color(240, 240, 240));
table.setEnabled(false);
model.addColumn("科目");
model.addColumn("成績");
try {
Connection conn = UseDatabase.getConnection();
PreparedStatement prest = conn.prepareStatement("SELECT * FROM user_"+userName);
ResultSet rs = prest.executeQuery();
while (rs.next()) {
model.addRow(new Object[] { rs.getString(1), rs.getInt(2) });
}
} catch (Exception e) {
e.printStackTrace();
}
JScrollPane jscrollPane = new JScrollPane(table);
jscrollPane.setBounds(50, 50, 400, 100);
stdScore.add(jscrollPane);
previous = new JButton("上一頁");
previous.setBounds(780, 450, 80, 25);
previous.setFont(new Font("", Font.PLAIN, 10));
stdScore.add(previous);
previous.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==previous) {
frame.dispose();
}
}
}