如何只允许在jTextField中引入数字?
“ AttributeSet无法解析为类型”
这就是为什么我试图使用另一种只允许数字的方法:
txtUsername.addKeyListener(new MyKeyListener());public class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent ke){
System.out.println("Key pressed code = "+ke.getKeyCode());
if (ke.getKeyCode()>=48 && ke.getKeyCode()<=57)
return true;
else
return false;
}}但是,当然,因为keyPressed方法有效,所以它不起作用void。因此,为了只在文本字段中打印数字该怎么办?
芜湖不芜
慕雪6442864
随时随地看视频慕课网APP
相关分类