获取错误:BodyMassApplet不是抽象的,不会覆盖抽象方法actionPerformed(ActionEvent)

时间:2014-02-24 09:53:01

标签: java abstraction

我一直收到这个错误,我似乎无法弄清楚为什么有任何想法?(不会编译) 这是一个从我的工作控制台应用程序构建的applet(教育原因)。 谢谢你们......

错误:BodyMassApplet不是抽象的,并且不会在ActionListener中覆盖抽象方法actionPerformed(ActionEvent)     public class BodyMassApplet extends Applet实现了ActionListener

代码:

/*
        Name : ****************
        Date : 13/02/14
        Reason : Bodymass calculator
        Chapter : 3
        Programs Name : BodyMassApplet.java

*/

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class BodyMassApplet extends Applet implements ActionListener
{
        //declare vars
        Image logo;//declare an image object
        int inches, pounds;
        double meters, kilograms, index;

        //construct components
        Label companyLabel = new Label ("THE SUN FITNESS CENTER BODY MASS INDEX CALCULATOR");
        Label heightLabel = new  Label("Enter your height to the nearest inch : ");
            TextField heightFeild = new TextField (10);
        Label weightLabel = new Label ("Enter your weight to the nearest pound : ");
            TextField weightFeild = new TextField (10);
        Button calcButton = new Button ("Calculate");
        Label outputLabel = new Label ("Click the Calculate button to see your Body Mass Index. ");

        public void init()
        {
            setForeground(Color.red);
            add(companyLabel);
            add(heightLabel);
            add(heightFeild );
            add(weightLabel);
            add(weightFeild);
            add(calcButton);
            calcButton.addActionListener(this);
            add(outputLabel);
            logo = getImage(getDocumentBase(),"log.gif");
        }//Close init method


        public void actionPerfomed(ActionEvent e)
        {
            inches = Integer.parseInt(heightFeild.getText());
            pounds = Integer.parseInt(weightFeild.getText());
            meters = inches /39.36;
            kilograms =pounds /2.2;
            index = kilograms / Math.pow(meters,2);
            outputLabel.setText("Your Body Mass Index Is" + Math.round(index)+ ".");
        }


        public void paint(Graphics g)
        {
            g.drawImage(logo,125,160,this);
        }







}//close applet class

1 个答案:

答案 0 :(得分:0)

这只是一个错字,你写了

public void actionPerfomed(ActionEvent e)

但你的意思是:

public void actionPerformed(ActionEvent e)

我建议使用像Eclipse这样的IDE,它会向你指出这个问题。