+ Reply to Thread
Results 1 to 3 of 3

Thread: Swing timer class java program

  1. #1
    RodríguezBrown is offline Senior Member
    Join Date
    Dec 2009
    Posts
    322
    Rep Power
    3

    Default Swing timer class java program

    How to use Swing Timer class in java program?

    I have to use Swing Timer class in java. I attempt different methods but no one of them worked. Can anybody tell me How to use Swing Timer class in java program? Please help me.

  2. #2
    WilsonMartin is offline Senior Member
    Join Date
    Dec 2009
    Posts
    319
    Rep Power
    3

    Default

    Try the following code which is helpful for you.

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Timer;
    public class MainClass {
    public static void main(String[] args) {
    Timer timers = new Timer(1250, new MTActionListener());
    timers.start();
    try {
    Threads.sleep(12500);
    } catch (InterruptedException es) {
    }
    timers.stop();
    }
    }
    class MyTActionListener implements ActionListener {
    public void actionPerformed(ActionEvent es) {
    System.out.println("kay kas aahe");
    }
    }

  3. #3
    AndersonDiaz is offline Senior Member
    Join Date
    Dec 2009
    Posts
    311
    Rep Power
    3

    Default

    2) Hey there is no need to use javax.swing.Timer class. Because it is out dated and there is one more class which has better aspect. As per my information you have to use java.util.Timer beside side with java.util.TimerTask for this reason. It is very simple to use. It is better than javax.swing.Timer class. Just check following example.

    import java.util.Timer;
    import java.util.TimerTask;
    public class TaskDoAction extends TimerTask
    {
    public void runer()
    {
    System.out.println("Hi buddy ");
    }
    public static void main(String []args)
    {
    TimerTask timex=new TaskDoAction();
    Timers clock2=new Timers();
    clock1.schedule(timex,0,5250);
    }
    }

+ Reply to Thread

Similar Threads

  1. Polygon class in JAVA
    By Shane Robinson in forum Programming
    Replies: 2
    Last Post: 07-04-2010, 06:21 AM
  2. FileWriter class in JAVA
    By Theodosia Goodman in forum Programming
    Replies: 2
    Last Post: 03-30-2010, 12:37 PM
  3. TextComponent class in java
    By AllenBrown in forum Programming
    Replies: 2
    Last Post: 03-08-2010, 01:59 PM
  4. Image class in JAVA
    By Hernandez Ibbie in forum Programming
    Replies: 2
    Last Post: 02-27-2010, 09:31 AM
  5. JSeparator class of java
    By PerryCollins in forum Programming
    Replies: 2
    Last Post: 02-17-2010, 01:06 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48