Hi
I get the following errors when I changed something - I don't know what, but these occur now.

Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
at sun.awt.Win32GraphicsConfig.getBounds(Native Method)
at sun.awt.Win32GraphicsConfig.getBounds(Win32GraphicsConfig.java:240)
at java.awt.Window.init(Window.java:368)
at java.awt.Window.<init>(Window.java:407)
at java.awt.Frame.<init>(Frame.java:402)
at java.awt.Frame.<init>(Frame.java:367)
at javax.swing.JFrame.<init>(JFrame.java:163)
at ExitJoke.<init>(ExitJoke.java:22)
at ExitJoke.<init>(ExitJoke.java:43) <-- Keeps repeating itself over and over


I had changed something, because befor I did it would keep repeating the exit screen without stopping, then eventually freezing the computer because some many screens were open at once. Here's the code.

import java.util.Timer;
   import java.util.TimerTask;
/**
 *
 * @author Mike
 */
public class ExitJoke extends javax.swing.JFrame {

 Timer timer;

       public ExitJoke ( int seconds ) {
         timer = new Timer ( ) ;
         timer.schedule ( new RemindTask ( ) , seconds*1000 ) ;
      }

       class RemindTask extends TimerTask {
          public void run ( ) {

            timer.cancel ( ) ; //Terminate the timer thread
          
         }
      }
     
      {

         new ExitJoke ( 5 ) ;//Time in seconds.

 System.exit(0);
      }

    /** Creates new form ExitJoke */
    public ExitJoke() {
        initComponents();
    }                      


        public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ExitJoke().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton btnJoke;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration                   

}

I didn't include the 'Generated Code' as I have not touched it, and its very long :P

Recommended Answers

All 3 Replies

L24-29 this is initialization
When you creates (in main method) new instance of ExitJoke the first executed code is L24-29. L26 here is "new ExitJoke", this executes code in L24.
Then your program work in loop L26-L24-L26....
Move code L24-29 to end of main constructor

Thank you, it works fine now :)

thanks quuba.
I learned that we should that create the object of class that initiate gui/frame.

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.