I am creating a simple GUI game (number guessing) in Java.
Apparently, I have a button called Give Up
.
When I click the Give Up
button, I want to display the answer on a textarea.
However, the targetNumber
variable is declared as private:
public class GameUtility {
private String targetNumber = "2543";
//rest of the code
}
class GiveUpButton implements ActionListener { //Inner class
public void actionPerformed(ActionEvent gEvent) {
GameUtility utility = new GameUtility();
textArea.append(utility.targetNumber); //How to access the value of targetNumber?
}
}
How can I access a value of a private variable?