Hello I have a simple issue that is not a compilation or runtime issue, but an aesthetic problem that I can't find a function for. Basically I've created a GUI window that visually represents a game board for my Reversi gameboard. I've implemented the GUI and the Reversi gameplay and it runs fine in the command window, and shows up the way I intend on the GUI window, the only issue is when I update my gameboard in the command window (where I initiate the move I wish to make), the GUI window does not repaint() and validate() unless I minimize then reopen the GUI window.
Here is some pseudocode so you can better understand:

while(gameRunning){
     //create GUI window
     ...
     //handle game-logic
     //update GUI with new gameboard layout
}

and that "update GUI" code

public void updateBoardGUI(char[][] gameBoard){
	removeAll();
	gameBoardGUI = gameBoard; //reset info completely
	repaint();
	validate();
}

So just to reiterate, this all works fine. The only issue is that I have to minimize and reopen the GUI window for the board to actually "refresh". What built in function is there so it automatically refreshes? If something like this doesn't exist, would creating a "refresh" button within the GUI help? How could I got about this?
Thanks!

Recommended Answers

All 4 Replies

try making a "thread" which updates and re validates your GUI with small regular intervals

With calling repaint, the GUI should call on paintComponent(Graphics g). Have you overridden that? Put a console output there to check if it is called.

On line 3 you update a variable gameBoardGUI to refer to the new char[][], but that won't change any Swing components. It seems you are missing a line or two of code here to update some Swing component with that new data.

put Board to the JPanel, then you only to

myCOntainer.remove(myPanel);
myCOntainer.revalidate();
myCOntainer.repaint();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.