/** Assignment:  Modify this file (previously SimpleApplet5)
 ** to include a title center at the top of the applet. 
 ** In addition, figure out which way (horizontally or 
 ** vertically) the two nested loops in the program are
 ** painting the color boxes, and then change the program
 ** so that it paints the color boxes in the opposite      
 ** direction. Also, edit MyApplet7.html in the  project 
 ** directory, to run the MyApplet7.class file you create, 
 ** and to look nice.                                      **/      
 
/** USE EXISTING JAVA CLASSES **/

import java.awt.*;
import java.applet.Applet;

/** EXTEND THE JAVA APPLET CLASS **/
public class MyApplet7 extends Applet{

 Font f = new Font("TimesRoman",Font.BOLD,18);
	    FontMetrics fm = getFontMetrics(f);
	   
	    
	    String s = "Look at the Pretty Boxes";
    
	    
	    

   int rval, gval, bval;                     // Define red, green, blue color variables.
   
    public void init()	
       {setBackground(Color.white);}          // Change the gray background to white.
       
    /** CREATE THE CURRENT FRAME **/

    public void paint(Graphics g)
    {int xstart = (size().width - fm.stringWidth(s)) / 2;
	    int ystart = 15;
	    
     g.setFont(f);
      g.drawString(s, xstart, ystart);
    
    
       {for (int j = 30; j < (size().height - 25); j += 30)   // Set up vertical spacing.
	  {for (int i = 35; i < (size().width - 25); i += 25)  // Set up horizontal spacing.
	     {rval =(int) Math.floor(Math.random()*256);      // Generate a random color
	      gval =(int) Math.floor(Math.random()*256);      // red, green, blue mix.
	      bval =(int) Math.floor(Math.random()*256);      // Note the "casting" here.
	      
		        			      
				       
	      g.setColor(new Color(rval,gval,bval));          // Paint a small box with
	      g.fillRect(i,j,20,20);                          // the current random color.
	      g.setColor(Color.black);                        // Paint a black border around 
	      g.drawRect(i-1,j-1,21,21);                      // the edge of the small box.
			}
		    }   
	        }	
	    }	     
	
    }