//developed by Dale Roberts 09/27/99

// Class library list
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class AlphabetGame extends Applet implements ActionListener
{
// Class constants
static final int LABEL_INDEX = 0;
static final int ANIMAL_INDEX = 1;
static final int LOCATION_INDEX = 2;
static final String MESSAGES[][] =
{ {"A", "Aye-Aye", "Madagascar"},
{"B", "Bald Eagle", "United States"},
{"C", "Caribou", "Arctic"},
{"D", "Dingo (wild dog)", "Australia"},
{"E", "Echidna (spiny anteater)", "Australia"},
{"F", "Flying Squirrel", "North America"},
{"G", "Gibbon", "Southeast Asia"},
{"H", "Hippopotamus", "Africa"},
{"I", "Ibex", "Asia"},
{"J", "Jaguar", " South America"},
{"K", "Kangaroo", "Australia"},
{"L", "Lemming", "Arctic"},
{"M", "Musk Ox", "Arctic North America"},
{"N", "Numbat", "South America"},
{"O", "Orangutan", "Bornea"},
{"P", "Polar Bear", "Arctic"},
{"Q", "Quokka", "Australia"},
{"R", "Reindeer", "Arctic"},
{"S", "Snowy Owl", "Arctic North America"},
{"T", "Tasmanian Devil", "Australia"},
{"U", "Unau (two-toed sloth)", "South America"},
{"V", "Vulture", "Africa"},
{"W", "Wolverine", "Labrador"},
{"X", "Xukazi", "Africa"},
{"Y", "Yapok", "Australia"},
{"Z", "Zebra", "Africa"},
{"About", "Enhanced Alphabet Game, 09/27/99", "About"}
};

// Class variables

// Labels
Label animalLabel;
Label locationLabel;

// Fonts
Font animalFont;
Font locationFont;

// Declare a panel to hold the buttons
Panel buttonPanel;

// Declare a button array
Button buttonArray[];

public void init()
{
// Instantiate the fonts
animalFont = new Font("SansSerif", Font.PLAIN, 20);
locationFont = new Font("SansSerif", Font.ITALIC, 20);

// Instantiate the labels
animalLabel = new Label();
locationLabel = new Label();

// Set label font and color
animalLabel.setFont(animalFont);
animalLabel.setBackground(Color.white);
animalLabel.setForeground(Color.black);
animalLabel.setAlignment(Label.CENTER);
locationLabel.setFont(locationFont);
locationLabel.setBackground(Color.blue);
locationLabel.setForeground(Color.yellow);
locationLabel.setAlignment(Label.CENTER);

// Instantiate and initialize the panel and button array
buttonPanel = new Panel();
buttonArray = new Button[MESSAGES.length];
buttonPanel.setLayout(new GridLayout(3,9));
for (int i = 0; i < MESSAGES.length; i++)
{
buttonArray[i] = new Button(MESSAGES[i][LABEL_INDEX]);
buttonArray[i].addActionListener(this);
buttonPanel.add(buttonArray[i]);
}

// Set the layout of the sandbox and add labels and panel
this.setLayout(new BorderLayout());
this.add(locationLabel, BorderLayout.NORTH);
this.add(animalLabel, BorderLayout.CENTER);
this.add(buttonPanel, BorderLayout.SOUTH);

} // end of init()

public void actionPerformed(ActionEvent e)
{
// Local variables
int i = 0;

// See which button was pressed
while (e.getSource() != buttonArray[i]) i++;

// i now points to selected button. Display its info
animalLabel.setText(MESSAGES[i][ANIMAL_INDEX]);
locationLabel.setText(MESSAGES[i][LOCATION_INDEX]);
} // end of actionPerformed()

} // end of Applet Alphabet Game