GUI之监听文本框回车动作

创建监听

KeyListener b=new KeyListener();
            jTextField1.addActionListener(b);
            jPasswordField1.addActionListener(b);
            jButton1.addActionListener(b);
public class KeyListener implements ActionListener {
            //重写ActionListener接口中的事件处理方法actionPerformed()
            public void actionPerformed(ActionEvent e) {
                Object source = e.getSource();
                if(source==jTextField1){
                    jPasswordField1.requestFocus();//跳转到文本框
                }
                if(source==jPasswordField1){
                    jButton1.doClick();//跳转到按钮
                }
            }}**

你可能感兴趣的:(学习java日常)