Results 1 to 8 of 8
  1. #1
    wizekraker is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Smile display count down timer

    Hello java users
    plz could you show me how make countdown timer display I have done this action script.. but I dont know how to do it in java

    actionscript:version:

    var timer = 10
    var totaltime;

    .....addeventlister.timer(10(the amout of time it executes, 1000(1 sec)

    totaltime = timer-1

    I need to know how to display simple countdown timer similar to this in Java plz and thank you if kind enough plz supply the code. I understand it more when give the code

    and plz dont say google becuz il already did that and non of it helped me

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I understand it more when give the code
    This really isn't a "give me the code" type site, but rather one where we help others learn to code in Java. So I won't tell you to Google this, but I will ask you to look at the Swing tutorial here:

    Swing Tutorial Index
    Using Swing Components

    And the Swing Timer tutorial: How To Use Swing Timers

    That should give you enough information to get you started. Then if you get stuck, please post your code and ask your questions about it.

    Luck!

  3. #3
    wizekraker is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    umm...could explain how to use this kind of timer and how to put the countdown timer function into it and could explain what following code does



    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */


    package timer;
    import java.util.Timer;
    import java.util.TimerTask;

    /**
    *
    * @author Owner
    */
    public class Reminder {
    Timer timer;
    int total = 5;
    int Time;


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


    class RemindTask extends TimerTask {
    public void run ( ) {

    Time = total - 5;
    System.out.println ( Time ) ;
    timer.cancel ( ) ; //Terminate the timer thread
    }
    }


    public static void main ( String args [ ] ) {
    System.out.println ( "About to schedule task." ) ;
    new Reminder ( 5 ) ;
    System.out.println ( "Task scheduled." ) ;
    }

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by wizekraker View Post
    umm...could explain how to use this kind of timer and how to put the countdown timer function into it and could explain what following code does
    No, because this code isn't even using a Swing Timer but rather a java.util.Timer and TimerTask, classes that won't help you for your goal. You really don't want to be blindly borrowing code from the net and ask others to explain it to you as you're far better off going to the tutorials that I linked you to above, putting in the effort and learning to code this yourself. Sorry to say but there are no short-cuts when it comes to learning how to code.

    Again much luck!

  5. #5
    wizekraker is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    okay... I got this so far:

    public class Reminder extends TimerTask
    {
    int time = 10;
    int totaltime;


    public void run()
    {
    System.out.println(time-= 1);
    }
    public static void main(String []args)
    {
    TimerTask toDo1=new Reminder();
    Timer clock1=new Timer();
    clock1.schedule(toDo1,0,1000);
    }
    }

    my only problem is how can make it so its woudlnt be doing

    9
    8
    7
    6
    5
    4
    and so on
    display count down timer
    instead i want it replace the spot i think i know this but...
    is the a method where you tell the direct coodinates where you want to print it

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    okay... I got this so far:

    public class Reminder extends TimerTask
    Stubborn little cuss, ain't you?

    db

  7. #7
    wizekraker is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    No, because this code isn't even using a Swing Timer but rather a java.util.Timer and TimerTask, classes that won't help you for your goal. You really don't want to be blindly borrowing code from the net and ask others to explain it to you as you're far better off going to the tutorials that I linked you to above, putting in the effort and learning to code this yourself. Sorry to say but there are no short-cuts when it comes to learning how to code.

    Again much luck!
    Quote Originally Posted by wizekraker View Post
    umm...could explain how to use this kind of timer and how to put the countdown timer function into it and could explain what following code does



    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */


    package timer;
    import java.util.Timer;
    import java.util.TimerTask;

    /**
    *
    * @author Owner
    */
    public class Reminder {
    Timer timer;
    int total = 5;
    int Time;


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


    class RemindTask extends TimerTask {
    public void run ( ) {

    Time = total - 5;
    System.out.println ( Time ) ;
    timer.cancel ( ) ; //Terminate the timer thread
    }
    }


    public static void main ( String args [ ] ) {
    System.out.println ( "About to schedule task." ) ;
    new Reminder ( 5 ) ;
    System.out.println ( "Task scheduled." ) ;
    }

    couls some one answer my quesetion plz

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Your question as I see it is how to create a timer that displays ... and I assume that this means that you wish to display the count-down timer in a GUI. If so, you'll want to use Swing and you'll want to use a Swing Timer (javax.swing.Timer) as I've recommended in my post above with link to the tutorial, not a java.util.Timer as you persist in asking about.

    If my assumptions are incorrect, please correct them. If they're correct, then have you checked out the links yet?

    Luck!

Similar Threads

  1. Stopping a Timer from Inside the timer
    By krishnan in forum Java Applets
    Replies: 2
    Last Post: 10-04-2010, 11:15 PM
  2. How to use a timer to count up or down.
    By caryr in forum AWT / Swing
    Replies: 5
    Last Post: 06-28-2009, 08:33 PM
  3. display histogram that count white pixels
    By TamTam in forum Java 2D
    Replies: 6
    Last Post: 02-14-2009, 09:26 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:46 PM
  5. making a count down timer using java
    By saytri in forum New To Java
    Replies: 3
    Last Post: 12-29-2007, 09:49 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
  •