改错。okBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub student a =new student(); String newpassword=pField.getText(); int c = 0; if (newpassword.equals("")) { JOptionPane.showMessageDialog(null, "新密码不能为空", "warning", JOptionPane.PLAIN_MESSAGE); } else { c = studentDao.studentUpdate(newpassword); if (c == 1) { JOptionPane.showMessageDialog(null, "更新记录成功", "成功", JOptionPane.PLAIN_MESSAGE); } } } });
时间: 2024-03-24 16:37:45 浏览: 57
改错后的代码如下:
```
okBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String newpassword = pField.getText();
int c = 0;
if (newpassword.equals("")) {
JOptionPane.showMessageDialog(null, "新密码不能为空", "warning", JOptionPane.PLAIN_MESSAGE);
} else {
studentDao studentDao = new studentDao();
c = studentDao.studentUpdate(newpassword);
if (c == 1) {
JOptionPane.showMessageDialog(null, "更新记录成功", "成功", JOptionPane.PLAIN_MESSAGE);
}
}
}
});
```
修改说明:
1. 在 actionPerformed 方法中实例化了 studentDao 对象,以便调用其方法。
2. 将 `student a = new student();` 改为 `studentDao studentDao = new studentDao();`,以便正确创建 studentDao 对象。
3. 将 `String newpassword = pField.getText();` 的位置移到了 `studentDao` 实例化前面,以便在执行更新操作前获取用户输入的新密码。
阅读全文