是否从textField(AWT)只能得到String? int iVal=new Integer(textField.getText()).intvalue(); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 int nText;nText = Integer.parseInt(textField.getText()); 再问gaoql(雪淞):如何检测textField控件中输入了非数字的非法数据,并弹出对话框(我不会在代码中动态生成警告对话框)intvalue()会抛出异常吗,若是,如何写代码? import javax.swing.*;............ int nI,nJ,nK; String str1; nJ = dSJTextField1.getText().length(); for (nI = 0;nI <= nJ;nI++) { str1 = dSJTextField1.getText().substring(nI,nI + 1); if (str1.equals("0") || str1.equals("1") || str1.equals("2") ...... || str1.equsls("9")) { } else { JOptionPane.showMessageDialog(this,"有非法字符存在"); return; } } ...... ......(做你想做的事情) 如果要检测异常的话,你捕捉一下啊,可以这样try{ int iVal=new Integer(textField.getText()).intvalue(); }catch(Exception e){ //弹出警告窗口 .........} 如果要检测异常的话,你捕捉一下啊,可以这样try{ int iVal=new Integer(textField.getText()).intvalue(); }catch(Exception e){ //弹出警告窗口 .........} 同意楼上的。那个竹之草写的什么垃圾代码,不要误人子弟另外,用不着new Integer(...)应该是这样:try{ iVal=Integer.parseInt(textField.getText());}catch(Number exception){ (new java.swing.JDialog("输入应该为数字")).show();}你试一下,不行再问我,这分我要定了 急! 30分求教,JAVA小程序 两个简单的问题 关于线程控制小球跳跃反弹的例子程序 如何将int型的数据转化为byte型数据 菜鸟问,高手答!! 用数组实现字符串的翻转 我怎么就不会创建自己的包啊?我明白包的作用 请高手们解决下面的问题 这个问题都没有人回答?不会吧!!! 外部命令的问题 to hexiaofeng()
nText = Integer.parseInt(textField.getText());
intvalue()会抛出异常吗,若是,如何写代码?
......
......
int nI,nJ,nK;
String str1;
nJ = dSJTextField1.getText().length();
for (nI = 0;nI <= nJ;nI++)
{
str1 = dSJTextField1.getText().substring(nI,nI + 1);
if (str1.equals("0") || str1.equals("1") || str1.equals("2") ...... || str1.equsls("9"))
{ }
else
{
JOptionPane.showMessageDialog(this,"有非法字符存在");
return;
}
}
......
......(做你想做的事情)
可以这样
try{
int iVal=new Integer(textField.getText()).intvalue();
}catch(Exception e){
//弹出警告窗口
.........
}
可以这样
try{
int iVal=new Integer(textField.getText()).intvalue();
}catch(Exception e){
//弹出警告窗口
.........
}
那个竹之草写的什么垃圾代码,不要误人子弟
另外,用不着new Integer(...)
应该是这样:
try{
iVal=Integer.parseInt(textField.getText());
}catch(Number exception){
(new java.swing.JDialog("输入应该为数字")).show();
}
你试一下,不行再问我,这分我要定了