【发布时间】:2013-12-21 20:51:32
【问题描述】:
我想使用NumberFormatException,但我的代码有错误,因为我的程序中有TextField 和一个按钮。如果在文本字段中输入数字,则没有任何问题。
如果您输入字母,我想收到错误消息但我不使用。请帮帮我?
我的代码
private JTextField t1=new JTextField(10);
private JButton o88 = new JButton("send");
try{
o88.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
int a = 0;
a = Integer.parseInt(t1.getText());
}
});
}
catch (NumberFormatException e){
System.out.println( e.getMessage());
}
【问题讨论】:
-
看起来您的可执行代码位于方法、构造函数或初始化程序之外。
标签: java swing exception parseint actionevent