import java.applet.Applet;
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import javax.swing.JApplet;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class AppletLifeCycle extends JApplet {
public AppletLifeCycle()throws HeadlessException {
super();
}
public void destroy() {
System.out.println("Applet start() is invoked!");
}
public String getAppletInfo() {
return "This is my default applet created by Eclipse";
}
public void init() {
getContentPane().setLayout(new FlowLayout());
getContentPane().add(new JLabel("Applet init() is invoked!"));
System.out.println("Applet init() is invoked!");
}
public void start() {
getContentPane().add(new JLabel("Applet start() is invoked!"));
System.out.println("Applet start() is invoked!");
repaint();
}
public void stop() {
System.out.println("Applet stop() is invoked!");
}
public static void main(String []args){
//Applet程序里面有了main方法后,程序就可以像Application一样运行了。
JApplet applet =new AppletLifeCycle();//实例化一个applet
JFrame frame=new JFrame("AppletLifeCycle");//实例化一个顶级窗口frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet);//将applet放到顶级窗口中
frame.setSize(200,100);
applet.init();
applet.start();
frame.setVisible(true);
}
}