Center of the Rectangle

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.
    int width  = getSize().width;
    int height = getSize().height;

Answer:

These statements get the width and height (in pixels) of the rectangle that the Web browser has allocated to the applet.

Center of the Rectangle

The width and height are needed to determine the size of the star that fits in the rectangle.

Next the applet sets the background color to white and the pen color to blue. The lines of the figure will be drawn with the pen.

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

public class SnowFlakeBasic extends Applet
{
  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;
    int min;
    
    setBackground( Color.white );   // set the background color
    gr.setColor  ( Color.blue  );   // set the drawing pen color
 
    // ensure that the star fits in the rectangle of the applet 
    if ( height > width )
      min = height;
    else
      min = width;
      
    drawStar( , , min/4 );  // draw star in center
  }
}

To draw a symmetrical star, find the minimum of the drawing area rectangle's width and height. Base the length of the radiating lines on this distance. The length could be min/2 if all we were drawing were the star, but let us make the length min/4 so that there is room for the rest of the snowflake.

Next the star is drawn in the center of the rectangle.

QUESTION 6:

Fill in the blanks so that the center of the star is the center of the rectangle.