我正在尝试创建一个简单的登录系统,我希望用户能够在他们按下回车按钮时继续下一部分,并且我设法让它在注册部分工作,这样当用户完成输入在他们的详细信息中,他们可以按回车键,程序进入下一部分,但我想要这样,当用户输入他们的登录详细信息时,他们可以按回车键,然后程序将执行下一部分代码。
card3 = new JPanel();
usernameFieldone = new JTextField(10);
usernameLabel = new JLabel("Username:");
usernameLabel.setLabelFor(usernameFieldone);
passwordFieldone = new JPasswordField(10);
passwordLabel = new JLabel("Password:");
passwordLabel.setLabelFor(passwordFieldone);
passwordFieldre = new JPasswordField(10);
passwordLabelre = new JLabel("Confirm Password: ");
passwordLabelre.setLabelFor(passwordFieldre);
passwordFieldre.addKeyListener(this);
OKButton = new JButton("OK");
OKButton.addActionListener(this);
backButton = new JButton("Back");
backButton.addActionListener(this);
public void keyReleased(KeyEvent e){
CardLayout cl = (CardLayout)(cards.getLayout());
if(e.getKeyCode()==KeyEvent.VK_ENTER){
if(
Register();
}
}`