当前位置: 代码迷 >> Java相关 >> 关于运行后出现的错误
  详细解决方案

关于运行后出现的错误

热度:265   发布时间:2006-07-09 23:44:14.0
关于运行后出现的错误
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
class EditWindow extends JFrame implements ActionListener
{
JTextField text1,text2,text3;
JPanel jpanel;
EditWindow(String s)
{
super(s);
setSize(300,250);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
text1=new JTextField(20);
text2=new JTextField(20);
text3=new JTextField(20);
text3.setEditable(false);
jpanel=new JPanel();
Container con=getContentPane();
jpanel.add(text1);
jpanel.add(text2);
jpanel.add(text3);
con.add(jpanel,BorderLayout.CENTER);
text1.addActionListener(this);
text2.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{

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)
{
JOptionPane.showMessageDialog( this,"Invalid Operand", "Invalid Number Format",
JOptionPane.ERROR_MESSAGE );//每次输入第一个数字时候,总是异常?为什么??
return;
}
}
}
public class Tan1
{
public static void main(String args[])
{
EditWindow win=new EditWindow("窗口");
}
}
搜索更多相关的解决方案: import  JTextField  awt  java  event  

----------------解决方案--------------------------------------------------------

没的问题 我这运行的好好的
我看你是有其他地方的错

你把public class Tan1 的public给去掉就可以了



希望大家以后不要发不规范的贴(贴名) 人家以后怎么查询帖子呢?

[此贴子已经被作者于2006-7-10 1:58:56编辑过]


----------------解决方案--------------------------------------------------------
  相关解决方案