为什么输入第一个数字时候总是出现异常???
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("窗口");
}
}