next up previous
Next: Implementation Up: In the Laboratory: Pig Previous: Problem Design: The PigLatin

Problem Design: PigLatinApplet

The design of PigLatinApplet should be similar to that of other applets we've built. It should contain a TextField for user input and a Label for prompting the user. Note that its interface (Figure 1) does not contain a Button, so the applet's action events will be generated when the user types the Enter key in the TextField. (See the In the Laboratory section in Chapter 5.)

PigLatinApplet should implement the ActionListener.actionPerformed() method to handle TextField actions. When the user types Enter, actionPerformed() should get the input from the TextField and pass to PigLatin.translate(), which will return a (Pig Latin) string. The applet should then append the result to the TextArea.

Recall that since we have patterned PigLatin after the Math class (and Integer class), there is no need to instantiate it in order to use its static methods. So to translate ``Hello World'' into Pig Latin we could simply write

    System.out.println(PigLatin.translate("Hello World"));

The translate() method is a class method -- a static method that is associated with the class itself.



Ralph Morelli {Faculty}
12/22/1999