swing 学生管理系统界面代码
时间: 2023-08-03 16:09:52 浏览: 40
以下是一个简单的 Swing 学生管理系统界面代码的示例:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class StudentManagementSystem extends JFrame {
// 定义组件
private JLabel nameLabel, ageLabel, genderLabel, classLabel;
private JTextField nameTextField, ageTextField;
private JComboBox<String> genderComboBox, classComboBox;
private JButton addButton, deleteButton, updateButton, searchButton;
private JTextArea resultTextArea;
// 初始化界面
public StudentManagementSystem() {
setTitle("学生管理系统");
setSize(500, 400);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 创建组件
nameLabel = new JLabel("姓名:");
ageLabel = new JLabel("年龄:");
genderLabel = new JLabel("性别:");
classLabel = new JLabel("班级:");
nameTextField = new JTextField(10);
ageTextField = new JTextField(10);
genderComboBox = new JComboBox<String>(new String[]{"男", "女"});
classComboBox = new JComboBox<String>(new String[]{"一班", "二班", "三班", "四班"});
addButton = new JButton("添加");
deleteButton = new JButton("删除");
updateButton = new JButton("修改");
searchButton = new JButton("查询");
resultTextArea = new JTextArea(10, 20);
// 设置布局
GridLayout layout = new GridLayout(6, 2);
setLayout(layout);
// 添加组件
add(nameLabel);
add(nameTextField);
add(ageLabel);
add(ageTextField);
add(genderLabel);
add(genderComboBox);
add(classLabel);
add(classComboBox);
add(addButton);
add(deleteButton);
add(updateButton);
add(searchButton);
add(resultTextArea);
// 添加事件监听器
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 添加学生信息的逻辑
}
});
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 删除学生信息的逻辑
}
});
updateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 修改学生信息的逻辑
}
});
searchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 查询学生信息的逻辑
}
});
}
public static void main(String[] args) {
new StudentManagementSystem();
}
}
```
注意:这个示例只是一个简单的界面代码,没有实现具体的逻辑。实际上,学生管理系统需要实现添加、删除、修改、查询等功能,需要编写更多的代码来实现。