0
當輸入鍵被按下時,如何執行我的loginButton
?我嘗試了幾件事,但沒有工作當輸入鍵被按下時執行登錄按鈕
public void actionlogin(){
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String roosterName = loginUser.getText();
String roosterPassw = loginPassw.getText();
if(roosterName.equals("admin") && roosterPassw.equals("admin")) {
Rooster gotoRooster = new Rooster();
gotoRooster.setVisible(true);
dispose();
} else {
JOptionPane.showMessageDialog(null,"Incorrect Username/Password");
loginUser.setText("");
loginPassw.setText("");
loginUser.requestFocus();
}
}
});
}
謝謝。有用。 –