In this version, the applet will present the user with a a scrambled word, such as "avja". The user will input a guess into a JTextField and click on a JTextButton. The applet will then check whether the guess is correct and report the result in a JTextArea.
Modify both ScramblePanelApplet and ScrambleGUIPanel so they interface with the Scramble class. Here are a list of required changes:
Java API Documentation
Look up the JPanel class and find a method that you can use to add a border to a panel. The method will be named something like setBorder(). If you can't find a method in the JPanel class, look in its immediate superclass. Remember that a class inherits the public methods of its superclasses and can use them as its own.
What is the immediate superclass of JPanel? You can find the answer by looking at the very beginning of the JPanel documentation. If you have trouble navigating the API, ask for help.
The type of border used in the demo is a TitledBorder. Look up this class in the API and find the simplest constructor that you can use to create a titled border. Preferably you want a constructor that lets you set its title. Note that the TitledBorder class belongs to the javax.swing.border package. This means you will have to add the following import statement to the beginning of your class definition:
import javax.swing.border.*;
Once you've found all the pieces, you will have to put them together. Here's an example of how you would add a titled border to the inputPanel, the panel that contains the prompt and the text field.
inputPanel.setBorder(new TitledBorder("Inputs"));
Try this out. And see how it looks. It's better to add borders to panels, rather than to text areas, or other components. So create additional panels, one for the control buttons and one for the display text area and add titled borders to them. Then add the buttons and the display to their respective panels. Then add the panels to the ScrambleGUIPanel (the main panel) in the North, Center, and South positions.
NOTE: Local vs. Global Variables. Where should you declare these additional JPanels? If a variable is only going to be used in one method, it is better to declare it locally. That way you don't clutter up your class definition with instance variables.
What action should your program take? When the user requests a new game, you have to create a new Scramble object. There is no need to declare a new variable for this. You can assign it to the Scramble instance variable, which will now just refere to a new object. Of course, you want to give this new object a new set of words. Then you have to issue a new prompt in the display area. Try to sample program to see how this should work. Obviously, this will only work once. We'll need to learn more Java in order to play an unlimited number of scramble games.
Before handing in your programs, be sure to document your source code.
Have your work checked by the laboratory instructor or TA. Print out and hand in a copy of your ScrambleGUIPanel.java.