学生管理系统Java图形用户界面
时间: 2023-12-25 08:04:40 浏览: 32
以下是一个学生管理系统的Java图形用户界面的示例:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class StudentManagementSystemGUI extends JFrame {
private JLabel nameLabel;
private JTextField nameTextField;
private JButton addButton;
private JTextArea displayTextArea;
public StudentManagementSystemGUI() {
// 设置窗口标题
setTitle("学生管理系统");
// 创建组件
nameLabel = new JLabel("姓名:");
nameTextField = new JTextField(20);
addButton = new JButton("添加");
displayTextArea = new JTextArea(10, 30);
// 设置布局管理器
setLayout(new FlowLayout());
// 添加组件到窗口
add(nameLabel);
add(nameTextField);
add(addButton);
add(displayTextArea);
// 添加按钮点击事件监听器
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = nameTextField.getText();
displayTextArea.append("添加学生:" + name + "\n");
nameTextField.setText("");
}
});
// 设置窗口大小和可见性
setSize(400, 300);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new StudentManagementSystemGUI();
}
}
```