Reputation: 11
I have a simple grid that places a square wherever the user clicks. The grid and access to the panes are held in a "Game" object.
This works:
private void buildClicked(int x, int y) {
panel.repaint();
game.buy(x, y);
}
This does not trigger a repaint:
private void buildClicked(int x, int y) {
game.getPanel().repaint();
game.buy(x, y);
}
If I make the panel a public variable of Game, this doesn't work either:
private void buildClicked(int x, int y) {
game.panel.repaint();
game.buy(x, y);
}
"getPanel" simply returns the same custom panel object that the top's "panel" object is referring to.
I would like to contain the panel in the Game object wrapper. Similarly, calling the repaint function inside the "buy" function doesn't work.
Why does the "repaint" function behave differently in the above examples?
Upvotes: 0
Views: 409
Reputation: 11
The comments under my question were exactly right. I had been declaring the panel separately in the Game object and the window itself. Another case of being caught up in new material and missing something basic. Thank you!
Upvotes: 1