Java学生管理系统删除界面代码
时间: 2023-08-03 07:09:44 浏览: 41
以下是一个简单的Java学生管理系统删除界面的代码示例:
```java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DeleteStudentGUI implements ActionListener {
private JFrame frame;
private JTextField idField;
private JButton deleteButton;
private JLabel statusLabel;
private StudentManager manager;
public DeleteStudentGUI(StudentManager manager) {
this.manager = manager;
frame = new JFrame("删除学生信息");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(300, 150);
frame.setLayout(new GridLayout(3, 1));
JPanel idPanel = new JPanel();
JLabel idLabel = new JLabel("学号:");
idField = new JTextField(10);
idPanel.add(idLabel);
idPanel.add(idField);
JPanel buttonPanel = new JPanel();
deleteButton = new JButton("删除");
deleteButton.addActionListener(this);
buttonPanel.add(deleteButton);
JPanel statusPanel = new JPanel();
statusLabel = new JLabel("");
statusPanel.add(statusLabel);
frame.add(idPanel);
frame.add(buttonPanel);
frame.add(statusPanel);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == deleteButton) {
String id = idField.getText().trim();
if (id.equals("")) {
statusLabel.setText("请输入学号");
return;
}
boolean success = manager.deleteStudent(id);
if (success) {
statusLabel.setText("删除成功");
} else {
statusLabel.setText("删除失败");
}
}
}
}
```
该代码创建了一个包含一个文本框、一个按钮和一个标签的窗口,用于输入要删除的学生学号并执行删除操作。在单击删除按钮时,该代码将获取文本框中的学号并调用学生管理器中的方法来删除该学生。操作结果将显示在标签中。请注意,此示例代码假定已经实现了名为StudentManager的学生管理器类,并且已经实现了删除学生的方法。
相关推荐
![](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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)