Copy/paste this code into a file

import java.awt.*;
import java.applet.*;

// this is a simple Java applet

// all applets are extentions of the class Applet
public class TestApplet extends Applet {

    // method paint displays the graphics of the applet
    public void paint(Graphics g) {
        // set the Color for drawing (default is black):
        // draw a rectangle:
	g.drawRect(100, 100, 200, 50);

Copy/paste this into a file TestApplet.html:

<APPLET CODE="TestApplet.class" HEIGHT=300 WIDTH=400></APPLET>

To run (on Windows):
  1. Open Command Prompt window. Go to the folder where your programs are: cd C:\myprograms (replace myprograms by the folder where you copied the files).
  2. Compile the code: javac in the Command Prompt window.
  3. Run it using appletviewer: appletviewer TestApplet.html.

This is an example from CSci 1211 course.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.