求纠正一下程序
import javax.swing.*;public class Qiuhe extends JFrame{
JFrame a =new JFrame("求和工具");
JPanel panel=new JPanel();
JTextField field1=new JTextField(8);
JButton button1=new JButton("+");
JTextField field2=new JTextField(8);
JButton button2=new JButton("=");
JTextField field3=new JTextField(8);
public Qiuhe()
{
panel.add(field1);
panel.add(button1);
panel.add(field2);
panel.add(button2);
panel.add(field3);
a.add(panel);
button2.addActionListener(new java.awt.event.ActionListener()
{ public void actionPerformed(java.awt.event.ActionEvent evt)
{
int x=Integer.parseInt(field1.getText())+Integer.parseInt(field2.getText());
field3.setText(Integer.toString(x));
}
});
}
public static void main(String[] args)
{
Qiuhe b=new Qiuhe();
b.setTitle("求和工具");
b.pack();
b.setDefaultCloseOperation(EXIT_ON_CLOSE);
b.setSize(400,100);
b.setVisible(true);
}
}程序没有错,但是为什么运行是结果出现的文本框不是计算器那样的呢?