// Johann Shudlick
// April 29, 1999
// Final Project
// Create an appicaiton for tutoring and testing elemtentary school kids

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

public class studyFrame extends Frame implements ActionListener
{
   private String stateName[] = { "GeoWhiz Presents:", "Arizona", "California", "Colorado", "Idaho", "Kansas", "Montana", "Nebraska", "Nevada", "New Mexico", "North Dakota", "Oklahoma", "Oregon", "South Dakota", "Texas", "Utah", "Washington", "Wyoming" };
   private String capitolName[] = { "The Wild West", "Phoenix", "Sacramento", "Denver", "Boise", "Topeka", "Helena", "Lincoln", "Carson City", "Santa Fe", "Bismark", "Oklahoma City", "Salem", "Pierre", "Austin", "Salt Lake City", "Olympia", "Cheyenne" };
   private Image statePic[];
   private Button forward, back, test, review;
   private GeoWhiz gw;
   private Font x, y;
   private reviewFrame r;
   public int index = 0;

   public studyFrame( GeoWhiz parent )
   {
      super( "Learn the States!!!" );
      
      setSize( 580, 420 );
      gw = parent;
      statePic = new Image[ 18 ];

      for( int i = 0; i < 18; i++)
         statePic[ i ] = parent.getImage( parent.getDocumentBase(), "state" + i + ".jpg" );

      setLayout( null );

      forward = new Button ( "Next State?" );
      add( forward );
      forward.addActionListener( this );
      forward.setBounds( 325, 345, 90, 30 );

      test = new Button ( "Test Now!" );
      add( test );
      test.addActionListener( this );
      test.setBounds( 225, 345, 90, 30 );

      review = new Button ( "Review More!" );
      add( review );
      review.addActionListener( this );
      review.setBounds( 125, 345, 90, 30 );

      back = new Button ( "Last State?" );
      add( back );
      back.addActionListener( this );
      back.setBounds( 25, 345, 90, 30 );

      x = new Font( "Arial Black", Font.BOLD, 36);
      y = new Font( "Coronet", Font.ITALIC, 24);

      addWindowListener( new WindowHide(this) );
   }

   public void paint( Graphics g )
   {
      g.drawRect( 5, 25, 315, 315 );

      g.drawImage( statePic[ index ], 10, 30, this);

      if( index != 0 )
      {
         g.setFont( x );
         g.drawString( "State:", 325, 150 );
         g.drawString( "Capital:", 325, 250 ); 
      }

      g.setFont( y );
      g.drawString( stateName[ index ], 350, 175 );
      g.drawString( capitolName[ index ], 350, 275 );
   }

   public void actionPerformed( ActionEvent e )
   {
      if( e.getSource() == forward )
      {
         index = (index + 1) % 18;
         repaint();
      }
      if( e.getSource() == back && index > 1 )
      {
         index--;
         repaint();
      }
      if( e.getSource() == review )
      {
         r = new reviewFrame( gw );
         r.setVisible( true );
         gw.getStudyFrame().setVisible(false);
      }
      if( e.getSource() == test )
      {
         gw.getTestFrame().setVisible(true);
         gw.getStudyFrame().setVisible(false);
      }

   }
}