Your company has assigned you the job of creating a visual game which
is a cross between 'Concentration' and Wheel of Fortune'. The screen should
be divided into an upper and lower part. In the lower section 36 JButtons
will send actions to 36 JTextAreas in the upper zone. The default background
of each text area should be set to contrast with what becomes the
background color of each text area when it is exposed. The buttons
should be numbered 1 to 36. A random number generator
should be created to display discrete numbers between 1 and 36 to indicate
which button to push which exposes it's corresponding text field.
In it's simplest version, All the buttons could be preloaded to display
a single puzzle. Better would be a menu selection which would enable loading
different puzzle variations. For the java wizards, the game would be slicker
if images in jpg, gif or html were used, more like in the 'Concentration'
game, with sections of the image exposed with each button push. The game
could have various auxillary buttons to expose a puzzle or rehide it.
Recommended Layout
Once you provide this stock layout, feel free to layout the game anyway you wish.
Make the 36 buttons fill a 3 by 12 grid layout on a JPanel, and add
it to the southern section of a JFrame's border layout.
Do the same for the text areas, adding them to the the center section
of the border layout. In the north zone add a title
for the game window. You should alter the font and point size of the
title. Place the random number generator' button and
text field to the right of the game title. Put the screen reset buttons
to the left.
One approach to differentiating
which button is being pushed and which text area should be activated.
public void actionPerformed(ActionEvent ae){
Object source=ae.getSource();
// using getSource() to differentiate
button's
if (source= = jb1){
j1Text.setText("A character or blank space
in the games puzzle line ");
}
else if (source = =jb2)
j2Text.setText("A character or blank space
in the games puzzle line ");
// etc.
}
}