【发布时间】: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