Get GUI of a different class to update continuously using java swing worker

94 views Asked by At

I am creating a new window of the MainWindow class from within a different class. The JFrame of the MainWindow class opens, and I can click my button, but the GUI does not update as it should after the button is clicked. I use SwingWorkers in this class, and if I run it on its own the GUI updates continuously. However, creating it from the other class, it is not updating properly, even after I called the creating using a SwingWorker.

    private void StartButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
    // TODO add your handling code here:

        WindowEvent winClose = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClose);
        StartGame doGame = new StartGame();
        doGame.execute();

}                                           

class StartGame extends SwingWorker<Void, Void>
{
   @Override
   public Void doInBackground()
   {

    try {
        MainWindow game = new MainWindow(num_respawns, hits, regen_secs, time, map);
        game.setVisible(true);
    } catch (IOException ex) {
        Logger.getLogger(GameSetup.class.getName()).log(Level.SEVERE, null, ex);
    }

       return null;
   }
   @Override
   public void done()
   {
       System.out.println("opening done");
   }

}
0

There are 0 answers