public void actionPerformed(ActionEvent e) { if (e.getSource().equals(searchButton)) { int id = Integer.parseInt(searchField.getText()); SQLHelp sqlHelp = new SQLHelp(); Student student = sqlHelp.queryStudent(id); if (student != null) { idField.setText(String.valueOf(id)); nameField.setText(student.getName()); genderField.setText(student.getGender()); dobField.setText(student.getDob()); batchField.setText(String.valueOf(student.getBatch())); } else { JOptionPane.showMessageDialog(QueryFrame.this, "无此学生"); } } else if (e.getSource().equals(searchButton2)) { this.setVisible(false); GUI.GUIjiemian();中的类及方法
时间: 2024-03-13 11:46:36 浏览: 25
这段代码是一个事件监听器,用于处理查询和返回按钮的点击事件。其中包含了对应的处理逻辑。
方法:
```java
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(searchButton)) {
int id = Integer.parseInt(searchField.getText());
SQLHelp sqlHelp = new SQLHelp();
Student student = sqlHelp.queryStudent(id);
if (student != null) {
idField.setText(String.valueOf(id));
nameField.setText(student.getName());
genderField.setText(student.getGender());
dobField.setText(student.getDob());
batchField.setText(String.valueOf(student.getBatch()));
} else {
JOptionPane.showMessageDialog(QueryFrame.this, "无此学生");
}
} else if (e.getSource().equals(searchButton2)) {
this.setVisible(false);
GUI.GUIjiemian();
}
}
```
这个方法接收一个ActionEvent对象,用于处理对应的事件。如果点击的是查询按钮,将从输入框中获取学生的学号,调用SQLHelp类的queryStudent方法查询学生信息,如果学生存在,则将对应的信息显示在界面上,否则弹出提示框显示“无此学生”。
如果点击的是返回按钮,将关闭当前窗口,并打开一个名为GUIjiemian的GUI界面。这个GUI界面的具体实现需要查看GUI类的其他部分。
相关推荐
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)