Java Applets - lifecycle - II

20 June 2008

Let 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.

del.icio.us:Java Applets - lifecycle - II  digg:Java Applets - lifecycle - II  spurl:Java Applets - lifecycle - II  wists:Java Applets - lifecycle - II  simpy:Java Applets - lifecycle - II  newsvine:Java Applets - lifecycle - II  blinklist:Java Applets - lifecycle - II  furl:Java Applets - lifecycle - II  reddit:Java Applets - lifecycle - II  fark:Java Applets - lifecycle - II  blogmarks:Java Applets - lifecycle - II  Y!:Java Applets - lifecycle - II  smarking:Java Applets - lifecycle - II  magnolia:Java Applets - lifecycle - II  segnalo:Java Applets - lifecycle - II  gifttagging:Java Applets - lifecycle - II

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

Leave a Reply