我在Java编程时遇到问题,出现错误,特向大家求教
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
class A extends Frame implements ActionListener {
TextField t1,t2,t3;
Button b1,b2,b3,b4;
A(String n){
super(n);
t1 = new TextField(10);
t2 = new TextField(10);
t3 = new TextField(10);
b1 = new Button("+");
b2 = new Button("-");
b3 = new Button("*");
b4 = new Button("/");
setLayout(new BorderLayout());
Panel p1 = new Panel();
Panel p2 = new Panel();
add(p1,BorderLayout.NORTH);
add(p2,BorderLayout.SOUTH);
FlowLayout f1 = new FlowLayout();
p1.setLayout(f1);
FlowLayout f2 = new FlowLayout();
p2.setLayout(f2);
p1.add(t1);
p1.add(t2);
p1.add(t3);
p2.add(b1);
p2.add(b2);
p2.add(b3);
p2.add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
setVisible(true);
setBounds(300,350,300,300);
pack();
validate();
}
public void actionPerformed(ActionEvent e){
int m = Integer.parseInt(t1.getText());
int n = Integer.parseInt(t2.getText());
if (e.getSource()==b1)
{ int h = m + n;
t3.setText(""+h);
}
if (e.getSource()==b2)
{ int h = m - n;
t3.setText(""+h);
}
if
(e.getSource()==b3)
{
int h =m * n;
t3.setText(""+h);
}
if
(e.getSource()==b4)
{
int h =m / n;
t3.setText(""+h);
}
}
}
public class F{
public static void main(String args[]){
A f = new A("计算");
f.setSize(600,600);
f.getContentPane().setBackground(Color.RED);
JPanel contentPane = new JPanel();
contentPane.setBackground(Color.yellow);
f.setVisible(true);
System.exit(0);
}
}
用TextPad编译时,却发现提示错误。我不知道该怎么修改。谢谢