import java.awt.*;import java.awt.event.*;public class Circle { Frame f; Label l1,l2; TextField tf1,tf2; Panel p1,p2,p3,p4; Button b1; public static void main(String[] args) { new Circle(); // TODO Auto-generated method stub } Circle(){ f=new Frame("这是窗体的名字"); l1=new Label("圆的半径:"); l2=new Label("圆的面积"); tf1=new TextField(20); tf2=new TextField(20); b1=new Button("计算"); p1=new Panel(); p2=new Panel(); p3=new Panel(); p4=new Panel(); b1.addActionListener(new ActionListener()//这句话一直报错 { public void Actionperformed(ActionEvent e) { int i; i=Integer.parseInt(tf1.getText()); tf2.setText(String.valueOf(3.1415926*2*i)); } }); p1.add(b1); p2.add(l1);p2.add(tf1); p3.add(l2);p3.add(tf2); p4.add(p3);p4.add(p1); f.add(p2,BorderLayout.NORTH); f.add(p4,BorderLayout.CENTER); f.setVisible(true); f.setSize(400, 170); f.setLocation(350, 450); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); }}
添加回答
举报
0/150
提交
取消