当前位置: 首页 > 知识库问答 >
问题:

获取错误:BodyMassApplet不是抽象的,并且不重写抽象方法actionPerformed(ActionEvent)

夏长卿
2023-03-14

错误:BodyMassApplet不是抽象的,并且不重写ActionListener公共类中的抽象方法actionPerformed(ActionEvent)BodyMassApplet扩展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个答案

葛宪
2023-03-14

这只是一个错别字,“你写道

public void actionPerfomed(ActionEvent e)

但你的意思是:

public void actionPerformed(ActionEvent e)

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

 类似资料: