【问题标题】:Get error: BodyMassApplet is not abstract and does not override abstract method actionPerformed(ActionEvent)获取错误:BodyMassApplet 不是抽象的,并且不会覆盖抽象方法 actionPerformed(ActionEvent)
【发布时间】:2014-02-24 09:53:00
【问题描述】:

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

错误: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

【问题讨论】:

    标签: java abstraction


    【解决方案1】:

    这只是一个错字,你写的

    public void actionPerfomed(ActionEvent e)
    

    但你的意思是:

    public void actionPerformed(ActionEvent e)
    

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

    【讨论】:

    • 不要回答与程序员无关的问题。不要制造更多的混乱。标记为离题和建议(在评论中)OP 以在 Stack Overflow 上提问,就像 gnat 所做的那样。
    • 谢谢大家,我在提出问题后几分钟就找到了它,但没有足够的意义来回答我自己的问题......是的,我知道 eclipse 虽然我正在做的课程附带软件我们必须使用它对 Java 课程的介绍,所以我必须使用基本编辑器,不能使用 IDE....可能听起来很奇怪,但这是 Java 交换,它是如何偏离主题的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    相关资源
    最近更新 更多