email me at borlaj@portlandschools.org
notes previous (09/07/06) submit the dump links  
 

Applets

 

An applet is a compiled program that is meant to run inside a web browser. It is perfect for quickly distributing applications with the internet. The applet is compiled to bytecode and an interpreter that is added on to the browser executes the byte code.

Key benefits:

  • Security
  • Ease of distribution
  • Powerful

Many uses of applets have been found, such as:

  • Banking
  • Games
  • Gradebook

The core part of an applet is below as created by blueJ:


import java.awt.*;
import javax.swing.*;

/**
 * Class TestApplet - write a description of the class here
 * 
 * @author (your name) 
 * @version (a version number)
 */
public class TestApplet extends JApplet
{

	/**
	 * Paint method for applet.
	 * 
	 * @param  g   the Graphics object for this applet
	 */
	public void paint(Graphics g)
	{
		// simple text displayed on applet
		g.setColor(Color.white);
		g.fillRect(0, 0, 200, 100);
		g.setColor(Color.black);
		g.drawString("Sample Applet", 20, 20);
		g.setColor(Color.blue);
		g.drawString("created by BlueJ", 20, 40);
	}

}

The paint method is called when the applet is run.

 

There are many methods that are included with the graphics class - see here.

 

Attempt this activity .