Results 1 to 8 of 8
Thread: display count down timer
- 11-12-2010, 01:02 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
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
-
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:I understand it more when give the code
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!
- 11-12-2010, 02:27 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
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." ) ;
}
-
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!
- 11-12-2010, 04:14 AM #5
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
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
- 11-12-2010, 10:08 AM #6
Stubborn little cuss, ain't you?okay... I got this so far:
public class Reminder extends TimerTask
db
- 11-12-2010, 06:42 PM #7
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
-
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
-
Stopping a Timer from Inside the timer
By krishnan in forum Java AppletsReplies: 2Last Post: 10-04-2010, 11:15 PM -
How to use a timer to count up or down.
By caryr in forum AWT / SwingReplies: 5Last Post: 06-28-2009, 08:33 PM -
display histogram that count white pixels
By TamTam in forum Java 2DReplies: 6Last Post: 02-14-2009, 09:26 PM -
How to cancel an individual timer in spite of canceling whole timer
By Java Tip in forum java.utilReplies: 0Last Post: 04-04-2008, 02:46 PM -
making a count down timer using java
By saytri in forum New To JavaReplies: 3Last Post: 12-29-2007, 09:49 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks