import java.awt.*; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class WordMatch extends Applet implements ActionListener, ItemListener { // Number of displayed cards and words. int numCards = 4; // Currently selected language. int curLanguage; // card[i] refers to the i'th word. int cards[]; // words[i] refers to the i'th card. int words[]; // Currently selected card. int curCard; // The components. Box soundBox; List languageList = new List(); Label statusBar = new Label("Ready"); Button scoreButton; Box[] cardBoxes; Box[] wordBoxes; // If true, the user has successfully matched all the words. boolean done; // links[i] == j -> cards[i] is linked to words[j]. int links[]; // Images of pictures. There is one image for each different word. Image images[]; // The dimensions of the images. They must all be the same size. int imageW, imageH; int numWords; String[] languages; String[][] dictionary; // Width of language list. int languageListW = 120; // Used to layout the components. int gap = 10; /** * Initialize the applet. Resize and load images. */ public void init() { imageW = Integer.parseInt(getParameter("image-w")); imageH = Integer.parseInt(getParameter("image-h")); // Count number of languages for (int i=1; ; i++) { if (getParameter("language"+i) == null) { languages = new String[i-1]; dictionary = new String[i-1][]; break; } } // Count total number of words, based on the first language. for (int i=0; i= 0) { Point pt1 = cardBoxes[i].getLocation(); Point pt2 = wordBoxes[links[i]].getLocation(); pt1.translate(imageW+gap, imageH/2); pt2.translate(-gap, imageH/2); g.drawLine(pt1.x, pt1.y, pt2.x, pt2.y); } } } public void itemStateChanged(ItemEvent evt) { if (!done) { statusBar.setText(null); } if (evt.getSource() == soundBox) { "rsrc/" + dictionary[0][cards[curCard]] + "." + languages[curLanguage] + ".au"); play(getCodeBase(), "rsrc/" + dictionary[0][cards[curCard]] + "." + languages[curLanguage] + ".au"); } // Was the event fired from one of the picture cards? for (int i=0; i