Results 1 to 3 of 3
  1. #1
    morfasto is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default Help with Timer Class

    Hello =)

    All I want to do is...

    private void jButton1_actionPerformed(ActionEvent e) {
    jLabel1.setText("Hello")

    // I WANT TO WAIT LIKE 10 SECONDS SO THAT THEN, THE JLABEL CHANGES TO:

    jLabel2.setText("Bye")
    }

    I am noob, sorry, hope you can help me =)

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,568
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by morfasto View Post
    Hello =)

    All I want to do is...

    private void jButton1_actionPerformed(ActionEvent e) {
    jLabel1.setText("Hello")

    // I WANT TO WAIT LIKE 10 SECONDS SO THAT THEN, THE JLABEL CHANGES TO:

    jLabel2.setText("Bye")
    }

    I am noob, sorry, hope you can help me =)
    You don't want to wait because you'll lock the AWT Event Dispatch thread (the thread that does all the painting and mouse event handling for you). Have a look at a Timer object (read the API documentation) and possibly the SwingUtilities class and its invokeLater( ... ) method.

    kind regards,

    Jos

  3. #3
    Msnforum is offline Member
    Join Date
    Sep 2008
    Posts
    7
    Rep Power
    0

    Default

    You can use the Swing Timer to time the 10 seconds.
    Find out more on javax.swing.Timer

    Example:
    Java Code:
    Timer timer = new Timer(speed, this);
    timer.setInitialDelay(pause);
    timer.start();

Similar Threads

  1. EJB Timer
    By mrjunsy in forum Advanced Java
    Replies: 0
    Last Post: 08-22-2008, 04:09 PM
  2. EJB Timer
    By mrjunsy in forum New To Java
    Replies: 0
    Last Post: 08-04-2008, 06:47 PM
  3. Replies: 0
    Last Post: 06-26-2008, 07:32 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:46 PM
  5. Replies: 0
    Last Post: 02-05-2008, 10:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •