/** * 11/12/02 - MusicHangman1 * * This class lets the user interact with a GUI to choose: * a) the basic 'flavour' (subject area) for the hangman game * b) which fields are to be guessed (and perhaps clued) within that flavour * c) the number of guesses allowed before hanging occurs * * Having resolved previous problems, this version is now ready to pull together * several custom classes in an all-embracing music hangman game. * * I've added audio files that play kill or reprieve music at the end of each game! */ import java.awt.*; import java.awt.event.*; import java.applet.*; import HangmanData; import HangmanFlavours; import QwertyPanel; import ScaffoldCanvas; public class MusicHangman1 extends Applet implements ActionListener, ItemListener, AdjustmentListener { //declare variables to do with overall layout structure TextField peek = new TextField("peek",25); //used in debugging only*************** CardLayout cards = new CardLayout(5,5); Panel pnlDeck = new Panel(cards); Panel pnlCard1, pnlCard2, pnlCard3; //universal font variables Font fntTitle = new Font("SansSerif", Font.BOLD, 20); Font fntUserCue = new Font("SansSerif", Font.ITALIC, 16); Font fntChoice = new Font("SansSerif", Font.PLAIN, 16); //for card1 -choosing the flavour Label lblTitle1, lblUserCue1; Choice choFlavour; Button btnFlavourChosen; Panel pnlCenter1; //for card2 -selecting guess and clue fields and number of guesses (lives) allowed Label lblTitle2, lblUserCue2, lblGuesses; Label[] lblField; TextField tfGuesses; Scrollbar sbGuesses; HangmanData data; Checkbox cbWantClue; Checkbox[] cbGuess, cbClue; CheckboxGroup cbgGuess, cbgClue; Panel pnlNorth2, pnlSouth2, pnlCenter2; Button btnFieldsChosen, btnBackTo1; int intSelectedGuess, intSelectedClue, intMaxGuesses; //for card 3 -playing the hangman game QwertyPanel qpKeys; ScaffoldCanvas scaffold; Label lblTitle3, lblUserCue3; TextField tfWordToGuess; Panel pnlLeft3Upper; String strWordToFind, //the word itself strWordSoFar; //as displayed to user (recalc after every button press) String[] strSingleLetters; //array of individual letters for checking boolean[] booCharFound; //flag array indicating which chars have already been found AudioClip acKill, acReprieve, acThought; //midi files /** *Entry point of Applet */ public void init() { this.setLayout(null); //use null layout for applet so that elements can be positioned pnlDeck.setSize(450,300); pnlDeck.setBackground(new Color(192,255,192)); this.add(pnlDeck); this.setBackground(Color.blue); this.setSize(450,300); setCard1(); acKill=getAudioClip(getDocumentBase(),"kill.MID"); acReprieve=getAudioClip(getDocumentBase(),"reprieve.MID"); acThought=getAudioClip(getDocumentBase(),"thought2.MID"); } /////// CARD 1 //////////////// private void setCard1() { //construct text elements lblTitle1 = new Label("Music Hangman"); lblTitle1.setFont(fntTitle); lblUserCue1 = new Label("Choose a subject:"); lblUserCue1.setFont(fntUserCue); //construct drop-down for selection of flavour choFlavour = new Choice(); choFlavour.setFont(fntChoice); for (int i=0;i0) { acThought.stop(); acKill.play(); } //show full word for (int i=0;i