-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChoiceSubject.java
More file actions
56 lines (46 loc) · 2.58 KB
/
ChoiceSubject.java
File metadata and controls
56 lines (46 loc) · 2.58 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
// ChoiceSubject.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ChoiceSubject extends JFrame {
private JList<String> subjectList;
private JCheckBox[] checkBoxes;
private JButton confirmButton;
public ChoiceSubject() {
setTitle("学生选课");
setSize(400, 300);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
String[] subjects = {"课序号:1,课程名称:math,课程地点:class,课程时间:8:00,授课教师:工号:001,姓名:张老师,性别:M",
"课序号:2,课程名称:english,课程地点:class,课程时间:10:00,授课教师:工号:002,姓名:李老师,性别:F",
"课序号:3,课程名称:history,课程地点:class,课程时间:14:00,授课教师:工号:003,姓名:刘老师,性别:F",
"课序号:4,课程名称:java,课程地点:class,课程时间:17:00,授课教师:工号:004,姓名:王老师,性别:M",
"课序号:5,课程名称:python,课程地点:class,课程时间:18:00,授课教师:工号:005,姓名:牛老师,性别:M",
};
subjectList = new JList<>(subjects);
subjectList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
checkBoxes = new JCheckBox[subjects.length];
for (int i = 0; i < subjects.length; i++) {
checkBoxes[i] = new JCheckBox(subjects[i]);
}
confirmButton = new JButton("确定");
confirmButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String selectedSubjects = "选修的课程:";
for (int i = 0; i < subjects.length; i++) {
if (checkBoxes[i].isSelected()) {
selectedSubjects += subjects[i] + " ";
}
}
// 假设当前登录的学生名字为"张三"
FileOperations.writeFile("selected_subjects.txt", "张三: " + selectedSubjects);
JOptionPane.showMessageDialog(null, "选课成功!", "提示", JOptionPane.INFORMATION_MESSAGE);
dispose();
}
});
JPanel panel = new JPanel(new BorderLayout());
panel.add(new JScrollPane(subjectList), BorderLayout.CENTER);
panel.add(confirmButton, BorderLayout.SOUTH);
add(panel);
}
}