Comments Required for Assignments

Here is an example of the comments required for every assignment. You will always need an opening comment that will have all the information that is shown in the example. You will always need a variable dictionary explaining what all your variables are used for. You need to explain what various parts of your program are doing. Be sure to use proper indentation (use a tab for each indentation). Do put a box around the opening comment and variable dictionary so they stand out from the rest of your program.

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

/*********************************************************
*  Name: Your Name                                       *
*  Course: ICS 4M  Pd. 5                                 *
*  Assignment #1                                         *
*  Purpose: One or two sentence purpose of the program.  *
*  Due Date: October 14, 2003                            *
*********************************************************/

public class AppletEx2 extends Applet implements ActionListener
{
   /*** Variable Dictionary ******************************
   * calls - number ot times paint has been called       *
   * b - the button that makes paint get called again    *
   ******************************************************/
   int calls = 0;
   Button b = new Button ("Click Me");
   
   /*** init *********************************************
   * Purpose: Set the background color and set up the    *
   *          button                                     *
   * Parameters: none                                    *
   * Returns: none                                       *
   ******************************************************/
   public void init()
   {
      setBackground(Color.green);
      // set up button
      add(b); 
      b.addActionListener(this);
   }
   
   /*** paint ********************************************
   * Purpose: Prints the number of times the button was  *
   *          clicked                                    *
   * Parameters: g - Graphics object for drawing on      *
   * Returns: none                                       *
   ******************************************************/
   public void paint(Graphics g)
   {
      String s = "Button has been clicked " + calls + " time";
      
      // Add 's' to times unless calls = 1
      if (calls != 1)
         s += "s";
      s += ".";
      g.drawString(s, 100,50);
   }
   
   /*** actionPerformed **********************************
   * Purpose: Deal with the button being pressed         *
   * Parameters: e - details about the button event      *
   * Returns: none                                       *
   ******************************************************/
   public void actionPerformed(ActionEvent e)
   {
      calls++;
      // make paint get called so that it can update the # of clicks
      repaint(); 
   }
}