gpt4 book ai didi

java - Jframe 内的输入法?

转载 作者:行者123 更新时间:2023-12-02 06:18:36 25 4
gpt4 key购买 nike

我在将学生管理器程序转换为 GUI 模式时遇到一些问题Student 类保存学生的一些信息

public class Student {
private String id,fullname,mark[],Subject,course[];
private Time bday;
private int n;

我创建了一个带有文本字段的 Jframe,就像 Student 类的属性和一个“Enter”按钮我希望当我单击按钮时,将学生导入到 Student 列表中但我仍然很困惑,不知道是否应该在单击按钮时将 input() 方法作为 ActionPerformed 放入 Jframe 中,还是将 Jframe 放入 input() 中Student 类的 方法

JButton btnNewButton = new JButton("ENTER");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String id = textField.getText();
String name = textField_1.getText();
String day1 = textField_2.getText();
String month1 = textField_7.getText();
String year1 = textField_8.getText();
int day = Integer.valueOf(day1);
int month = Integer.valueOf(month1);
int year = Integer.valueOf(year1);
Time bday = new Time(day,month,year);
String email = textField_3.getText();
String acc = textField_4.getText();
String pass = textField_5.getText();
String course1 = textField_6.getText();
int coursen = Integer.valueOf(course1);

}
});

最佳答案

不确定您打算用这个 input() 方法做什么,但是在您的按钮操作执行代码中,您可以解析输入并实例化您的 Student 对象(假设您的 Student 类包含相关的 setter 方法),例如:

 public void actionPerformed(ActionEvent arg0) {
Student student = new Student();
student.setId(textField.getText());
student.setName(textField_1.getText());
...
...

// then here you could possibly add this Student object in a collection that you would have as an instance variable of your JFrame class, eg:
studentList.add(student);
}

关于java - Jframe 内的输入法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55850514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com