设计一个学生信息录入的程序界面。学生信息量包括ID(学号)、name(姓名)、sex(性别)、birthday(生日)、home(籍贯)和result(入学成绩)。
时间: 2024-06-13 20:04:56 浏览: 67
以下是一个学生信息录入的程序界面的设计,其中包括ID(学号)、name(姓名)、sex(性别)、birthday(生日)、home(籍贯)和result(入学成绩)的输入框和提交按钮。用户可以在输入框中输入学生信息,点击提交按钮将学生信息保存到文件中。
```java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class StudentInfoInput extends JFrame implements ActionListener {
private JLabel idLabel, nameLabel, sexLabel, birthdayLabel, homeLabel, resultLabel;
private JTextField idField, nameField, sexField, birthdayField, homeField, resultField;
private JButton submitButton;
public StudentInfoInput() {
setTitle("学生信息录入");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
idLabel = new JLabel("ID(学号):");
nameLabel = new JLabel("name(姓名):");
sexLabel = new JLabel("sex(性别):");
birthdayLabel = new JLabel("birthday(生日):");
homeLabel = new JLabel("home(籍贯):");
resultLabel = new JLabel("result(入学成绩):");
idField = new JTextField(20);
nameField = new JTextField(20);
sexField = new JTextField(20);
birthdayField = new JTextField(20);
homeField = new JTextField(20);
resultField = new JTextField(20);
submitButton = new JButton("提交");
submitButton.addActionListener(this);
JPanel panel = new JPanel(new GridLayout(7, 2));
panel.add(idLabel);
panel.add(idField);
panel.add(nameLabel);
panel.add(nameField);
panel.add(sexLabel);
panel.add(sexField);
panel.add(birthdayLabel);
panel.add(birthdayField);
panel.add(homeLabel);
panel.add(homeField);
panel.add(resultLabel);
panel.add(resultField);
panel.add(submitButton);
add(panel);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == submitButton) {
String id = idField.getText();
String name = nameField.getText();
String sex = sexField.getText();
String birthday = birthdayField.getText();
String home = homeField.getText();
String result = resultField.getText();
// 将学生信息保存到文件中
// ...
}
}
public static void main(String[] args) {
new StudentInfoInput();
}
}
```
阅读全文