Skeletal JApplet

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
Historical topic: Java appletsModern web browsers do not run Java applets. The Applet API was deprecated for removal before Java 25 and was removed in Java 26. Treat applet examples on this page as historical object-oriented/GUI examples; for new desktop interfaces use Swing where appropriate or JavaFX/OpenJFX.

Answer:

class JApplet

Skeletal JApplet

Here is the skeleton for our applet:

import javax.swing.JApplet;
import java.awt.* ;
import java.lang.Math ;

public class SnowFlakeBasic extends JApplet
{
  Graphics graph;
   
  // draw a star consisting of six lines of length size
  // radiating from the point (x,y)
  //
  private void drawStar( int x, int y, int size )
  {
    .  .  .  .
  }
         
  public void paint ( Graphics gr )
  { 
    graph = gr;
    int width  = getSize().width;
    int height = getSize().height;

    .  .  .  .  .

    drawStar( . . . . );
  }
}

We extend the JApplet class and override the paint() method. The paint() method is called when the browser needs to fill in the applet's part of the screen.

QUESTION 5:

(Lucky Guess Department: ) What do you suppose the following does?

    int width  = getSize().width;
    int height = getSize().height;