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.

Changing appearance of the terrain button

Watch Your Step will need to change the appearance of the terrain button when the terrain is revealed.

  1. Add a public method called reveal(). It should take one parameter, a boolean called reveal, and return nothing.
  2. Set revealed to the value of reveal.
  3. If revealed is true:
  • If the terrain button hides a hole, set the background color to black. Use JButton's setBackground() method.
  • If the terrain button does not hide a hole:
    • Set the background color to cyan. Use JButton's setBackground() method.
    • If holes exist next to the terrain button, set the text nextToHoles. (Hint: use JButton's setText() method. To convert the integer value in nextToHoles to a string, add the integer to an empty string.)
  1. Otherwise: Set the background color to null using JButton's setBackground() method and set the text to an empty string using JButton's setText() method.
    ...
 
  _______________ reveal(_________) {
    revealed = _________;
    if(_________) {
      if(_________) {
        setBackground(__________________);
      }
      else {
        setBackground(__________________);
        if (nextToHoles _______) {
          setText(__________________);
        }
      }
    }
    else {
      setBackground(______);
      setText(_________);
    }
  }
}

Get hands-on with 1200+ tech skills courses.