okBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub String password = pField.getText(); int c = 0; if (password.equals("")) { JOptionPane.showMessageDialog(this, "新密码不能为空", "warning", JOptionPane.PLAIN_MESSAGE); } else { c = studentDao.studentUpdate(password); if (c == 1) { JOptionPane.showMessageDialog(this, "更新记录成功", "成功", JOptionPane.PLAIN_MESSAGE); } } } });
时间: 2024-04-01 08:31:35 浏览: 16
这段代码是一个按钮监听器的实现,监听器被添加到一个名为okBtn的按钮上。当用户点击该按钮时,actionPerformed方法将被调用,该方法首先获取名为pField的文本框中输入的字符串作为密码,然后检查密码是否为空。如果密码为空,将弹出一个警告对话框。否则,将调用studentDao的方法来更新学生的密码,并根据返回的结果显示相应的消息框。
相关问题
btn_huan.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub new ReturnFrm().setVisible(true); } });
这段代码是 Java Swing 中的事件处理代码,用于处理按钮的点击事件。当按钮被点击时,会执行 actionPerformed() 方法中的代码。在这段代码中,当按钮被点击时,会创建一个 ReturnFrm 的实例并将其设置为可见。ReturnFrm 是一个窗口类,该类的实例显示了一个返回按钮,用于返回到上一个窗口。
改正代码。okBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub String password = pField.getText(); int c = 0; if (password.equals("")) { JOptionPane.showMessageDialog(this, "新密码不能为空", "warning", JOptionPane.PLAIN_MESSAGE); } else { c = studentDao.studentUpdate(password); if (c == 1) { JOptionPane.showMessageDialog(this, "更新记录成功", "成功", JOptionPane.PLAIN_MESSAGE); } } } });
okBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String password = pField.getText();
int c = 0;
if (password.equals("")) {
JOptionPane.showMessageDialog(null, "新密码不能为空", "warning", JOptionPane.PLAIN_MESSAGE);
} else {
c = studentDao.studentUpdate(password);
if (c == 1) {
JOptionPane.showMessageDialog(null, "更新记录成功", "成功", JOptionPane.PLAIN_MESSAGE);
}
}
}
});
在这个代码中,我把原来的this改成了null,因为在这个地方使用this不会产生正确的效果。此外,我也把警告对话框的提示信息从"新密码不能为空"改成了"密码不能为空",因为这个对话框的提示信息应该更通用。
相关推荐
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.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)