Results 1 to 4 of 4

Thread: Timer on swing

  1. #1
    finzaiko is offline Member
    Join Date
    Jan 2009
    Posts
    6
    Rep Power
    0

    Default Timer on swing

    hallo all..

    i try use looping every minuts execute some method, to delay that i use thread.sleep() but if i click the button (jButton3 as an example below), other component can not execute that looping, how can use timer every some minuts do the method?

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
    int a = 0;
    do {
    try {
    Thread.sleep(200);
    } catch (InterruptedException ex) {
    Logger.getLogger(example01.class.getName()).log(Le vel.SEVERE, null, ex);
    }
    System.out.println(a);
    String b = Integer.toString(a); <<--when running jLabel2 can not change looping ex. 0123..
    jLabel2.setText(b);
    a++;
    } while (a<4);
    }

    anyone know how timer on swing, give me an example?

    tq b4..
    sorry about my english

    Rgds,
    Finz

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Did you know how to implement the timer in Swing?

    Java Code:
        public void myTimer(int time) {
            Timer timer = new Timer(time, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    // do the process
                }
            });
            timer.start();
        }

  3. #3
    finzaiko is offline Member
    Join Date
    Jan 2009
    Posts
    6
    Rep Power
    0

    Default

    i dont know yet im new one in java but i try this

    Tq

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Inside a Timer thread loop,how to refresh a JTable in swing
    By neha_negi in forum Threads and Synchronization
    Replies: 3
    Last Post: 09-04-2009, 02:45 AM
  2. Timer in Swing app - refreshing label
    By qoqosz in forum New To Java
    Replies: 5
    Last Post: 03-09-2009, 03:17 AM
  3. [SOLVED] Swing Timer issue
    By Doctor Cactus in forum New To Java
    Replies: 6
    Last Post: 03-03-2009, 01:25 PM
  4. EJB Timer
    By mrjunsy in forum New To Java
    Replies: 0
    Last Post: 08-04-2008, 07:47 PM
  5. Replies: 0
    Last Post: 04-04-2008, 03:46 PM

Posting Permissions

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