package doItMyself;
// <applet code=App.class height=100 width=200></applet>
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class App extends Applet{
private static final long serialVersionUID = 1L;
Button apple = new Button("press me");
public void init(){
add(apple);
apple.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println(e.paramString()+" pressed");
}
});
}
public static void main(String[] args) {
App a=new App();
a.init();
}
}
上面这一段程序中,add()方法为什么能够直接用,而前面不需要类或对象限定?
------解决方案--------------------
因为App 继承了Applet,add方法已经由Applet实现好了,所以你不需要再另外定义