比如说在登录框中,输完用户密码后直接回车就相当于单击了确定按钮,这个怎么实现?
输入完成一个文本框中的数据回车后下一个文本框获得焦点,这个又怎么实现?各位老大能不能贴段实现此功能的代码上来,谢谢了!!!
输入完成一个文本框中的数据回车后下一个文本框获得焦点,这个又怎么实现?各位老大能不能贴段实现此功能的代码上来,谢谢了!!!
解决方案 »
- UDP编程: 发送一个UDP包后,然后进入接收状态,但有时收不到回应包
- 用计算机颠覆你小学学的知识 2-1你都不知道等于几。。。
- JAVA如何更新文件的修改时间(如PHP的touch函数)
- 关于 的问题
- catch(Exception ex) Exception是BOOL值吗??
- 关于java socket 接受c语言发送的数据包问题
- 学JAVA中又有迷惑啦
- java中有关字符编码的问题
- 用JCreator开发Java项目到底怎样?
- 想问一下,frame.dispose的方法,系统对frame做了什么?
- java文件读取问题
- Exception in thread "main" java.lang.NullPointerException
jsp的话就onkeyDown事件
jsp的话就onkeyDown事件--------就是这样的
import javax.swing.*;
import java.awt.*;
class DefaultButton{
public static void main( String[] args ){
JFrame frame = new JFrame("DefaultButton");
frame.setLayout( new FlowLayout() );
final JTextField textField1 = new JTextField(10);
final JTextField textField2 = new JTextField(10);
JButton button = new JButton ("默认按钮,使下一个文本框获得焦点");
button.addActionListener( new ActionListener(){
public void actionPerformed( ActionEvent e){
if( textField1.hasFocus() )
textField2.requestFocusInWindow();
else
textField1.requestFocusInWindow();
}
});
frame.add(button);
frame.getRootPane().setDefaultButton(button);
frame.add(textField1);
frame.add(textField2);
frame.setLocationRelativeTo(null);
frame.pack();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setVisible(true);
}
}
http://haolla.com/wy
import javax.swing.*;
import java.awt.event.*;class TrasverseFocusUsingEnter implements ActionListener
{
JFrame mainFrame;
JPanel mainPanel;
JTextField textField1;
JTextField textField2;
public TrasverseFocusUsingEnter(){
mainFrame = new JFrame ( );
mainPanel = new JPanel ();
textField1 = new JTextField(10);
textField2 = new JTextField(10);
textField1.addActionListener( this );
textField2.addActionListener( this );
mainPanel.add( textField1 );
mainPanel.add( textField2 );
mainFrame.getContentPane().add( mainPanel );
mainFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
mainFrame.pack();
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible( true );
}
public void actionPerformed( ActionEvent e ){
FocusManager.getCurrentManager().focusNextComponent( (JTextField)e.getSource() );
}
public static void main(String[] args)
{
new TrasverseFocusUsingEnter(); }
}