import java.applet.*; import java.awt.*; /* *************************************************************** Bert G. Wachsmuth June 3, 1996 The JokePlayer class of the JokeClient program. This object plays the joke interactively inside the JokeClient applet's list box and joke control button. *************************************************************** */ public class JokePlayer extends Thread { private static int WAITING = 0; private static int DONE_KNOCK = 1; private static int DONE_Clue = 2; private static int DONE_PUNCH = 3; private static int GET_CLUE = 4; private static int GET_PUNCH = 5; private static int DONE = 6; private Button Control; private List Jokes; private String Clue; private String Punch; private String DefaultButtonLabel; private int status = WAITING; /* *************************************************************** */ public JokePlayer(Button _Control, List _Jokes, String _Clue, String _Punch, String _DefaultButtonLabel) { Clue = _Clue; Punch = _Punch; Control = _Control; Jokes = _Jokes; DefaultButtonLabel = _DefaultButtonLabel; start(); } /* *************************************************************** */ public void run() { while (true) { if (status == WAITING) { Jokes.addItem("Knock,Knock!"); Control.setLabel("Who's there?"); status = DONE_KNOCK; } if (status == GET_CLUE) { Jokes.addItem(Clue); Control.setLabel(Clue + " who?"); status = DONE_Clue; } if (status == GET_PUNCH) { Jokes.addItem(Punch); Control.setLabel(DefaultButtonLabel); status = DONE; stop(); } try { sleep(500); } catch(InterruptedException e) {} } } /* *************************************************************** */ public boolean handleButton(Object arg) { if ("Who's there?".equals(arg)) { Jokes.addItem("--> Who's there?"); status = GET_CLUE; return true; } if ((Clue + " who?").equals(arg)) { Jokes.addItem("--> "+Clue+" who?"); status = GET_PUNCH; return true; } return false; } /* *************************************************************** */ }