
/*
   Review.java
   A review of the java concepts that we have
   learned so far.
   (c) 1996 Burton Rosenberg
   For Univ. of Miami Math 220/317, 
   10 Sept 1996
*/

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

public class Review extends Applet {

   // Constants
   final static int NONE = 0 ;
   final static int CIRCLE = 1 ;
   final static int SQUARE = 2 ;
   final static int TRIANGLE = 3 ;

   // instance variables
   int figure = CIRCLE ;
   Button pushForCircle, pushForSquare, pushForTriangle ;

   public void init() {
      // make buttons
      pushForCircle = new Button("Circle") ;
      pushForSquare = new Button("Square") ;
      pushForTriangle = new Button("Triangle") ;
      add(pushForCircle) ;
      add(pushForSquare) ;
      add(pushForTriangle) ;
      validate() ;
   }

   public boolean action( Event evt, Object arg ) {
      int f = NONE ;

      if ( evt.target==pushForCircle ) 
         f = CIRCLE ;
      else if ( evt.target==pushForSquare ) 
         f = SQUARE ;
      else if ( evt.target==pushForTriangle ) 
         f = TRIANGLE ;
 
      if ( f==NONE ) return false ;
      figure = f ;
      repaint() ;
      return true ;

   }

   public void paint( Graphics gc ) {

      int xCent, yCent, r ;
      Dimension d = this.size() ;
      xCent = d.width/2 ;
      yCent = d.height/2 ;
      r = (xCent+yCent)/2 ;
      xCent -= r/2 ;
      yCent -= r/2 ;
      
      switch ( figure ) {
         case CIRCLE:
            gc.setColor( Color.red ) ;
            gc.fillOval( xCent, yCent, r, r ) ;
            break ;
         case SQUARE:
            gc.setColor( Color.blue ) ;
            gc.fillRect( xCent, yCent, r, r ) ; 
            break ;
         case TRIANGLE:
            gc.setColor( Color.green ) ;
            int [] x = { xCent, xCent+r/2, xCent+r } ;
            int [] y = { yCent+r, yCent, yCent+r} ;
            gc.fillPolygon( x, y, 3 ) ; 
            break ;
      }
   }

   public String getAppletInfo() {
       return "Review.java by Burt Rosenberg, Sept 10, 1996" ;  
   }

}
