0

How to dispose the JFrame after few sec and go to other JFrame? I had tried to put the this.dispose() but it did not work and still not dispose it.

Below will show where I had placed the dispose method.

int good = 3 ;
public Dloading2() {
    this.getContentPane().setBackground(Color.white);
    initComponents();

    Timer timer = new Timer();

    TimerTask task = new TimerTask()
            {
                public void run()
                {                           
                    if(good == 3)
            {    
                ConfirmationDeposit cust = new ConfirmationDeposit();
                  cust.setVisible(true);    
                  //this.dispose();
                  cancel();
            }                                               
                }           
            };  
    timer.scheduleAtFixedRate(task, 3000, 1000);
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 3
    1- Swing is NOT thread safe, you should never create or modify the UI elements from outside the Event Dispatching Thread, use a `SwingWorker` or Swing `Timer` instead; 2- See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556); 3- Make sure that the `defaultCloseOperation` is set correctyl; 4- Consider providing a [runnable example](https://stackoverflow.com/help/mcve) which demonstrates your problem. This will result in less confusion and better responses – MadProgrammer Dec 19 '14 at 01:37
  • 2
    Ugh, just don't do it as it's a terrible GUI design. User a CardLayout to swap views driven by a Swing Timer. – Hovercraft Full Of Eels Dec 19 '14 at 01:41
  • thank respond.. i try make it better btw i juz a starter java – Choo Brandon Dec 19 '14 at 01:49

0 Answers0