// 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 reviewFrame extends Frame implements ItemListener, ActionListener
{
private int num, order[], stateOrder[], capitolOrder[], picOrder[], stateIndex, capitolIndex, picIndex;
private String stateName[] = { "GeoWhiz", "Arizona", "California", "Colorado", "Idaho", "Kansas", "Montana", "Nebraska", "Nevada", "New Mexico", "North Dakota", "Oklahoma", "Oregon", "South Dakota", "Texas", "Utah", "Washington", "Wyoming" };
private String capitolName[] = { "", "Phoenix", "Sacramento", "Denver", "Boise", "Topeka", "Helena", "Lincoln", "Carson City", "Santa Fe", "Bismark", "Oklahoma City", "Salem", "Pierre", "Austin", "Salt Lake City", "Olympia", "Cheyenne" };
private String picName[];
public boolean used[];
private GeoWhiz gw;
private CheckboxGroup stateNames, capitolNames, picNames;
private Checkbox states[], capitols[], pics[], temp1, temp2, temp3;
private int stateX = 25, stateY = 25, capX = 150 , capY = 25, picX = 275, picY = 25, seconds = 150;
private Image map;
private Button test, study, again;
private reviewFrame z;
private Label hint,ins1, ins2, ins3;
reviewFrame( GeoWhiz parent)
{
super( "Review What You've Learned!!!" );
setSize( 640, 400 );
addWindowListener( new WindowDispose(this) );
setLayout( null );
gw = parent;
map = gw.getImage( gw.getDocumentBase(), "numberedMap.jpg" );
hint = new Label( "<-- Try to beat the clock!!!" );
add( hint );
hint.setBounds( 455, 300, 275, 25 );
ins1 = new Label( "TO REVIEW: Click on the name, capital, and" );
add( ins1 );
ins1.setBounds( 395, 330, 275, 10 );
ins2 = new Label( "location for each state. Text will dim if" );
add( ins2 );
ins2.setBounds( 395, 341, 275, 10 );
ins3 = new Label( "three corresponding options are checked." );
add( ins2 );
ins2.setBounds( 395, 352, 275, 10 );
test = new Button ( "Test Now!" );
add( test );
test.addActionListener( this );
test.setBounds( 395, 265, 75, 25 );
study = new Button ( "Study More!" );
add( study );
study.addActionListener( this );
study.setBounds( 475, 265, 75, 25 );
again = new Button ( "Try Again!" );
add( again );
again.addActionListener( this );
again.setBounds( 555, 265, 75, 25 );
picName = new String[ 18 ];
for( int i = 1; i < 18; i++)
picName[ i ] = new String( "Number " + i );
order = new int[18];
stateOrder = new int[18];
picOrder = new int[18];
capitolOrder = new int[18];
used = new boolean[18];
ResortArray();
stateNames = new CheckboxGroup();
states = new Checkbox[ 18 ];
for( int i = 1; i < 18; i++)
{
stateOrder[i] = order[i];
states[ i ] = new Checkbox( stateName[ stateOrder[i] ], stateNames, false );
states[ i ].addItemListener(this);
add( states[ i ] );
states[ i ].setBounds( stateX, stateY, 100, 15 );
stateY = stateY + 20;
}
ResortArray( );
capitolNames = new CheckboxGroup();
capitols = new Checkbox[ 18 ];
for( int i = 1; i < 18; i++)
{
capitolOrder[i] = order[i];
capitols[ i ] = new Checkbox( capitolName[ capitolOrder[i] ], capitolNames, false );
capitols[ i ].addItemListener(this);
add( capitols[ i ] );
capitols[ i ].setBounds( capX, capY, 100, 15 );
capY = capY + 20;
}
ResortArray( );
picNames = new CheckboxGroup();
pics = new Checkbox[ 18 ];
for( int i = 1; i < 18; i++)
{
picOrder[i] = order[i];
pics[ i ] = new Checkbox( picName[ picOrder[i] ], picNames, false );
pics[ i ].addItemListener(this);
add( pics[ i ] );
pics[ i ].setBounds( picX, picY, 100, 15 );
picY = picY + 20;
}
}
public void paint( Graphics g )
{
g.drawRect( 395, 25, 232, 232 );
g.drawRect( 395, 300, 40, 25 );
g.drawImage( map, 396, 26, 230, 230, this );
g.drawString( "" + seconds, 405, 320 );
if( seconds > 0)
{
try
{
Thread.sleep( 1000 );
}
catch ( InterruptedException exception)
{
System.out.println( exception.toString() );
}
seconds--;
repaint();
}
else
hint.setText( "Looks like the clock beat you..." );
}
public void actionPerformed( ActionEvent e )
{
if( e.getSource() == again )
{
z = new reviewFrame( gw );
z.setVisible( true );
gw.getReviewFrame().setVisible(false);
}
if( e.getSource() == test )
{
gw.getTestFrame().setVisible(true);
gw.getReviewFrame().setVisible(false);
z.setVisible( false );
}
if( e.getSource() == study )
{
gw.getReviewFrame().setVisible(false);
gw.getStudyFrame().setVisible(true);
z.setVisible( false );
}
}
public void itemStateChanged( ItemEvent e )
{
temp1 = stateNames.getSelectedCheckbox();
temp2 = capitolNames.getSelectedCheckbox();
temp3 = picNames.getSelectedCheckbox();
for( int i = 1; i < 18; i++ )
{
if( temp1 == states[ i ] )
stateIndex = i;
if( temp2 == capitols[ i ] )
capitolIndex = i;
if( temp3 == pics[ i ] )
picIndex = i;
}
if( stateOrder[ stateIndex ]== capitolOrder[ capitolIndex ] && stateOrder[ stateIndex ]== picOrder[ picIndex ] )
{
states[ stateIndex ].setEnabled( false );
capitols[ capitolIndex ].setEnabled( false );
pics[ picIndex ].setEnabled( false );
}
}
public void ResortArray( )
{
for( int i = 1; i < 18; i++ )
{
num = ( 1 + (int)(Math.random() * 17 ) );
while( used[ num ] )
num = ( 1 + (int)(Math.random() * 17 ) );
order[ i ] = num;
used[ num ] = true;
}
for( int i = 1; i < 18; i++ )
used[ i ] = false;
}
}