阅读更多
方法一:passwardField.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
if (passwardField.getText().length() == 0) {
System.out.println("clear!!!");
okButton.setEnabled(false);
}
}
public void keyTyped(KeyEvent e) {
if (passwardField.getText().length() != 0) {
System.out.println("passwardField");
okButton.setEnabled(true);
}
}
});
方法二:
passwardField.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
if (passwardField.getText().length() != 0) {
System.out.println("passwardField");
okButton.setEnabled(true);
} else {
okButton.setEnabled(false);
System.out.println("false");
}
}
});