Add Terrain Buttons to the Window and Change Their Appearance
Learn how to change the color and text of the button and add it in the window.
We'll cover the following
Changing appearance of the terrain button
Watch Your Step will need to change the appearance of the terrain button when the terrain is revealed.
- Add a public method called
reveal()
. It should take one parameter, a boolean calledreveal
, and return nothing. - Set
revealed
to the value ofreveal
. - If
revealed
is true:
- If the terrain button hides a hole, set the background color to black. Use
JButton
'ssetBackground()
method. - If the terrain button does not hide a hole:
- Set the background color to cyan. Use
JButton
'ssetBackground()
method. - If holes exist next to the terrain button, set the text
nextToHoles
. (Hint: useJButton
'ssetText()
method. To convert the integer value innextToHoles
to a string, add the integer to an emptystring
.)
- Set the background color to cyan. Use
- Otherwise:
Set the background color to
null
usingJButton
'ssetBackground()
method and set the text to an empty string usingJButton
'ssetText()
method.
...
_______________ reveal(_________) {
revealed = _________;
if(_________) {
if(_________) {
setBackground(__________________);
}
else {
setBackground(__________________);
if (nextToHoles _______) {
setText(__________________);
}
}
}
else {
setBackground(______);
setText(_________);
}
}
}
Get hands-on with 1200+ tech skills courses.