java里如何限制输入的字符
初学java,近来做了个类似于qq的聊天登录框,其他都还好,只是“帐户”一栏不知道怎么限制输入字母和符号(帐户由纯数字组成),程序代码如下,望编程高手能够帮我加几行代码来...
初学java,近来做了个类似于qq的聊天登录框,其他都还好,只是“帐户”一栏不知道怎么限制输入字母和符号( 帐户由纯数字组成 ),程序代码如下,望编程高手能够帮我加几行代码来限制帐户栏字母和数字的输入,谢谢!!!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextFieldTest extends JFrame {
private JTextField textField1, textField2, textField3;
private JPasswordField passwordField;
private JButton button;
public TextFieldTest()
{
super( "请输入您的帐号" );
Container container = getContentPane();
container.setLayout( new FlowLayout() );
textField1 = new JTextField( "帐号", 3 );
textField1.setEditable( false );
container.add( textField1 );
textField2 = new JTextField( 10);
container.add( textField2 );
textField3 = new JTextField( "密码", 3 );
textField3.setEditable( false );
container.add( textField3 );
passwordField = new JPasswordField( 10 );
container.add( passwordField );
button = new JButton("登录");
container.add( button );
setSize( 200, 130 );
setVisible( true );
}
public static void main( String args[] )
{
TextFieldTest application = new TextFieldTest();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}
我想在用户输入帐号后,判断是否为数字,不是则弹出警告 展开
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextFieldTest extends JFrame {
private JTextField textField1, textField2, textField3;
private JPasswordField passwordField;
private JButton button;
public TextFieldTest()
{
super( "请输入您的帐号" );
Container container = getContentPane();
container.setLayout( new FlowLayout() );
textField1 = new JTextField( "帐号", 3 );
textField1.setEditable( false );
container.add( textField1 );
textField2 = new JTextField( 10);
container.add( textField2 );
textField3 = new JTextField( "密码", 3 );
textField3.setEditable( false );
container.add( textField3 );
passwordField = new JPasswordField( 10 );
container.add( passwordField );
button = new JButton("登录");
container.add( button );
setSize( 200, 130 );
setVisible( true );
}
public static void main( String args[] )
{
TextFieldTest application = new TextFieldTest();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}
我想在用户输入帐号后,判断是否为数字,不是则弹出警告 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询