I have a simple JPanel for tic-tac-toe, drawing lines... so class TTT extends JPanel, and holds a GameLogic object inside.
all is good, application is a JFrame in Main adding TTT and all good.
BUT, when i want to restart a new game,
I call "restart" in my TTT which basiclly does : gameLogic = new GameLogic(); & repaint();
now my data array is clean and it should paint only lines..
any way Windows is not changed at all.
I've tried everything with no luck. Any suggestions?
GameBoard.java:
public class GameBoard extends javax.swing.JPanel {
private GameBoardLogic GameLogic;
//.....
public void Restart()
{
GameLogic = new GameBoardLogic();
removeAll();
repaint();
}
Main.java:
public class Main {
private static GameBoard TTT;
private static JFrame application;
public static void main(String[] args) {
application = new JFrame("Tic-Tac-Tow");
TTT = new GameBoard();
application.add(TTT);
application.setSize(350, 350);
application.setVisible(true);
//.....
if ( JOptionPane.showConfirmDialog(null, "Do you want to play again?") ==
JOptionPane.YES_OPTION )
{
application.removeAll();
TTT.Restart();
application.add(TTT);
application.validate();
}
This works for me
panel.removeAll();
//add your elements
revalidate();
repaint();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With