Java Applets - lifecycle - II
20 June 2008Let me present an applet example.
import java.applet.Applet; import java.awt.Graphics; public class HelloWorld extends Applet { StringBuffer buffer; public void init() { buffer = new StringBuffer(); addItem("initializing... "); } public void start() { addItem("starting... "); } public void stop() { addItem("stopping... "); } public void destroy() { addItem("preparing for unloading..."); } private void addItem(String newWord) { System.out.println(newWord); buffer.append(newWord); repaint(); } public void paint(Graphics g) { g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); g.drawString(buffer.toString(), 5, 15); } }
Run this applet from your IDE (Eclipse) and see the messages on the console.
An applet can react to major events in the following ways:
It can initialize itself.
It can start running.
It can stop running.
It can perform a final cleanup, in preparation for being unloaded.
Hope this helps.
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: Java Applets - lifecycle - II