pics.java Code

/*
 * pics.java
 *
 * Created on September 24, 2000, 8:25 AM
 */
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;

/**
 *
 * @author  hunt, jan
 * @version 
 */
public class pics extends java.applet.Applet implements ItemListener, ActionListener {
    String states[] = { "Wisconsin", "Colorado", "Kentucky", "Michigan", "Rhode Island", "California" };
    String cities[][] = {{ "Madison", "Lodi", "Sun Prairie", "Milwaukee", "Green Bay" },
                         { "Denver", "Fort Collins", "Colorodo Springs", "Durango", "Grand Junction" },
                         { "Frankfort", "Lexington", "Louisville", "Bowling Green", "Paducah" },
                         { "Lansing", "Detroit", "Dearborn", "Grand Rapids", "Olivet" },
                         { "Providence", "Warwick", "Westerly", "Woonsocket", "Kingston" },
                         { "Sacramento", "Los Angeles", "Eureka", "San Francisco", "San Diego"}};
   
    Image imgStates[] = new Image[6];
    Image imgClipArt[] = new Image[10];
    Choice choState = new Choice(); //simple constructor, no parameters for State
    Choice choCity = new Choice(); //simple constructor for City
    String strCity = "Madison";

    
    public void init () {
        Font fntMain = new Font("Verdana", Font.BOLD, 12);
        setFont(fntMain); //sets the font for the entire applet
        Font fntChoice = new Font("Verdana", Font.PLAIN, 15);
        choState.setFont(fntChoice);//set smaller font for choice box
        choCity.setFont(fntChoice);//set smaller font for choice box
            
        //populate the choice box for State
        for(int i=0; i < states.length; i++) 
            choState.add(states[i]);
        //add the choice box to the applet
        add(choState);
        choState.addItemListener(this);
        //set up the images of the states
        URL codebase = getCodeBase();
        imgStates[0] = getImage(codebase, "wis.gif");
        imgStates[1] = getImage(codebase, "col.gif");
        imgStates[2] = getImage(codebase, "ken.gif");
        imgStates[3] = getImage(codebase, "mic.gif");
        imgStates[4] = getImage(codebase, "ri.gif");
        imgStates[5] = getImage(codebase, "cal.gif");

        //populate the choice box for City
        for(int i=0; i < cities[0].length; i++) {
            choCity.add(cities[0][i]);
        }//end for loop for wisconsin cities
        //add the choice box to the applet
        add(choCity);
        choCity.addItemListener(this);
    }//end init()

    public void itemStateChanged(ItemEvent e) { 
        //this is for the item listener 
        if(e.getSource() == choState){
            choCity.removeAll();
            String strState = choState.getSelectedItem();
            int istate = choState.getSelectedIndex(); 
            switch(istate) {
                case 1: 
                   for(int i = 0; i < cities[1].length; i++)
                   choCity.add(cities[1][i]);
                   strCity = "Denver";
                   break;
                case 2:
                   for(int i = 0; i < cities[2].length; i++)
                   choCity.add(cities[2][i]);
                   strCity = "Frankfort";
                   break;
                case 3:
                   for(int i = 0; i < cities[3].length; i++)
                   choCity.add(cities[3][i]);
                   strCity = "Lansing";
                   break;
                case 4:
                   for(int i = 0; i < cities[4].length; i++)
                   choCity.add(cities[4][i]);
                   strCity = "Providence";
                   break;
                case 5:
                   for(int i = 0; i < cities[5].length; i++)
                   choCity.add(cities[5][i]);
                   strCity = "Sacramento";
                   break;
                case 0:
                   for(int i = 0; i < cities[0].length; i++)
                   choCity.add(cities[0][i]);
                   strCity = "Madison";
                   break;
        }//end iState switch
        }//end if chostate
        else if(e.getSource() == choCity) {
            strCity = choCity.getSelectedItem();
            int icities = choCity.getSelectedIndex();
            //System.out.println(icities);
        }//end choCity if
         repaint();
    }//end itemStateChanged
    
       
    public void actionPerformed(final java.awt.event.ActionEvent p1) {
        //use this if I have a button
    }//end actionPerformed
    
    public void paint(Graphics g) {
        g.drawString("Click on the State name or City name.", 45,65);//directions
        int state = choState.getSelectedIndex();//whatever state is picked
        g.drawImage(imgStates[state], 70, 140, this);//draw that state using index of
            URL codebase = getCodeBase();
            imgClipArt[0] = getImage(codebase, "bk_star.gif");
            imgClipArt[1] = getImage(codebase, "bl_star.gif");
            imgClipArt[2] = getImage(codebase, "blustar.gif");
            imgClipArt[3] = getImage(codebase, "grnstar.gif");
            imgClipArt[4] = getImage(codebase, "red_star.gif");
            imgClipArt[5] = getImage(codebase, "redball.gif");
            imgClipArt[6] = getImage(codebase, "star_gold.gif");
            imgClipArt[7] = getImage(codebase, "star_small.gif");
            imgClipArt[8] = getImage(codebase, "wh_star.gif");
            imgClipArt[9] = getImage(codebase, "GB.gif");
            
        if(strCity == "Madison") {
            g.drawImage(imgClipArt[0], 160, 255, this);
        }//end madison if
        else if(strCity == "Lodi") {
            g.drawImage(imgClipArt[8], 155, 245, this);
        }//end if lodi
        else if(strCity == "Sun Prairie") {
            g.fillOval(167, 260, 8, 8 );
        }//end sun p if
        else if(strCity == "Milwaukee") {
            g.fillOval(180, 260, 8, 8 );
        }//end milwaukee if
        else if(strCity == "Green Bay") {
            g.drawImage(imgClipArt[9], 165, 200, this);
        }//end if green bay
        else if(strCity == "Denver") {
            g.drawImage(imgClipArt[2], 150, 200, this);
        }//end if den
        else if(strCity == "Fort Collins") {
            g.fillOval(155, 195, 8, 8 );
        }//end madison if
        else if(strCity == "Colorodo Springs") {
            g.fillOval(160, 240, 8, 8 );
        }//end if cs
        else if(strCity == "Durango") {
            g.fillOval(125, 265, 8, 8 );
        }//end if dura
        else if(strCity == "Grand Junction") {
            g.fillOval(120, 210, 8, 8 );
        }//end if gj
        else if(strCity == "Frankfort") {
            g.drawImage(imgClipArt[3], 175, 220, this);
        }//end if frank
        else if(strCity == "Lexington") {
            g.fillOval(185, 215, 8, 8 );
        }//end if lex
        else if(strCity == "Louisville") {
            g.fillOval(130, 225, 8, 8 );
        }//end if louis
        else if(strCity == "Bowling Green") {
            g.fillOval(130, 245, 8, 8 );
        }//end if bg
        else if(strCity == "Paducah") {
            g.fillOval(120, 235, 8, 8 );
        }//end if padu
        else if(strCity == "Detroit") {
            g.fillOval(195, 275, 8, 8 );
        }//end if motor city
        else if(strCity == "Dearborn") {
            g.fillOval(190, 270, 8, 8 );
        }//end if dear
        else if(strCity == "Lansing") {
            g.drawImage(imgClipArt[4], 175, 270, this);
        }//end if lansing
        else if(strCity == "Grand Rapids") {
            g.fillOval(150, 245, 8, 8 );
        }//end if gr
        else if(strCity == "Olivet") {
            g.fillOval(180, 275, 8, 8 );
        }//end if olivet
        else if(strCity == "Providence") {
            g.drawImage(imgClipArt[7], 155, 175, this);
        }//end if prov
        else if(strCity == "Warwick") {
            g.fillOval(165, 200, 8, 8 );
        }//end if war
        else if(strCity == "Westerly") {
            g.fillOval(170, 210, 8, 8 );
        }//end if west
        else if(strCity == "Woonsocket") {
            g.fillOval(155, 150, 8, 8 );
        }//end if woon
        else if(strCity == "Kingston") {
            g.fillOval(150, 275, 8, 8 );
        }//end if king
        else if(strCity == "Sacramento") {
            g.drawImage(imgClipArt[8], 100, 200, this);
        }//end if la
        else if(strCity == "Eureka") {
            g.fillOval(130, 245, 8, 8 );
        }//end if eure
        else if(strCity == "Los Angeles") {
            g.fillOval(140, 280, 8, 8 );
        }//end if sac
        else if(strCity == "San Francisco") {
            g.fillOval(95, 230, 8, 8 );
        }//end if sf
        else if(strCity == "San Diego") {
            g.fillOval(155, 290, 8, 8);
        }//end if sd

    }//end paint
}//end class pics