标题:为什么输入第一个数字时候总是出现异常???
取消只看楼主
大嘴先生2
Rank: 1
等 级:新手上路
威 望:2
帖 子:815
专家分:0
注 册:2006-4-17
 问题点数:0 回复次数:1 
为什么输入第一个数字时候总是出现异常???
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.regex.*;
class EditWindow extends JFrame implements DocumentListener
{
JTextArea text1,text2,text3;
JPanel jpanel;
EditWindow(String s)
{
super(s);
setSize(200,250);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
text1=new JTextArea(1,10);
text2=new JTextArea(1,10);
text3=new JTextArea(1,10);
text3.setEditable(false);
jpanel=new JPanel();
Container con=getContentPane();
jpanel.add(text1);
jpanel.add(text2);
jpanel.add(text3);
con.add(jpanel,BorderLayout.CENTER);
(text2.getDocument()).addDocumentListener(this);
(text1.getDocument()).addDocumentListener(this);
setVisible(true);
}
public void changedUpdate(DocumentEvent e)
{
text3.setText(null);
double oper1=0,oper2=0;
try
{
oper1=Double.parseDouble(text1.getText());
oper2=Double.parseDouble(text2.getText());
text3.setText("="+String.valueOf(oper1+oper2));
}

catch(NumberFormatException ee)
{
System.out.println("产生异常");

}




}
public void removeUpdate(DocumentEvent e)
{
changedUpdate(e);
}
public void insertUpdate(DocumentEvent e)
{
changedUpdate(e);
}
}
public class Tan
{
public static void main(String args[])
{
EditWindow win=new EditWindow("窗口");
}
}
搜索更多相关主题的帖子: import 数字 java awt JTextArea 
2006-07-08 20:54
大嘴先生2
Rank: 1
等 级:新手上路
威 望:2
帖 子:815
专家分:0
注 册:2006-4-17
得分:0 

你能说的再祥细一点吗?
还是有点不明白???


骑白马的未必是王子,也可能是唐僧;有翅膀的未必是天使,也可能是鸟人。
2006-07-08 22:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-77283-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021749 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved