为了账号安全,请及时绑定邮箱和手机立即绑定

addActionListener(new ActionListener()问题

addActionListener(new ActionListener()问题

诗酒趁年华4 2017-12-09 10:50:24
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); } } ); }}
查看完整描述

1 回答

已采纳
?
HZK135

TA贡献10条经验 获得超3个赞

你没有实现ActionListener接口的方法-->方法名写错了Actionperformed()应该是actionPerformed()

查看完整回答
反对 回复 2017-12-09
  • 1 回答
  • 0 关注
  • 2076 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信