编程论坛
注册
登录
编程论坛
→
JAVA论坛
缺少方法主体如何处理
hhl0006
发布于 2015-07-24 08:12, 1314 次点击
错误:缺少方法主体,或声明抽象。public void actionPerformed(ActionEvent e);
8 回复
#2
calix
2015-07-24 09:57
正常类中的方法都是要加方法体的
接口和抽象类中可以只声明,由子类进行实现
#3
hhl0006
2015-07-24 14:08
如何将程序上传到论坛?添加附件无法上传。
#4
hhl0006
2015-07-24 14:26
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class HelloGuiWorld extends Applet implements ActionListener
{
Button pushButton;
Label greetingLabel;
String helloString=new String("您好,GUI世界!");
String goodbyeString=new String("再见!");
public void init()
{
pushButton=new Button("按压");
add(pushButton); //add()方法将GUI组件添加到小应用程序的显示区域。
pushButton.addActionListener(this);
//使用addActionListener()方法,按钮就注册一个listener事件。当该事件发生时,就被收听到,然后就调用相应的方法actionPerformed()。
greetingLabel=new Label(helloString);
add(greetingLabel);
}
public void actionPerformed(ActionEvent e);
{
if(greetingLabel.getText().equals(helloString))
{
greetingLabel.setText(goodbyeString);
}
else
{
greetingLabel.setText(helloString);
}
greetingLabel.repaint();
}
}
#5
hhl0006
2015-07-24 14:27
请问,如何修改?
#6
calix
2015-07-24 15:19
public void actionPerformed(ActionEvent e);
多了一个分号“;”,去掉就行了
#7
hhl0006
2015-07-24 17:02
谢谢!
#8
不懂才问
2015-07-25 08:40
学习了
#9
z664007782
2015-07-25 23:19
1