Timer

Timer

View Answers

December 6, 2008 at 3:55 AM

Hi friend,


import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimerDemo extends JFrame implements ActionListener {
ProgressMonitor progress;
static int counter = 0;
Timer timer;
public SimpleDateFormat TIME = new SimpleDateFormat("HH:mm:ss");
private static final int START_TIME = 0000;
int count = 100;

public TimerDemo() {
super("Progress bar timer Demo");
setSize(250, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
progress = new ProgressMonitor(null, " ", "Initializing . . .", 00, 100);
timer = new Timer(1000, this);
timer.start();
progress.setNote("Operation left " + count + "");
setVisible(true);
}

public static void main(String args[]) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}

UIManager.put("ProgressMonitor.progressText", "Demo");
new TimerDemo();
}

public void actionPerformed(ActionEvent e) {
// Invoked by the timer every half second. Simply place
SwingUtilities.invokeLater(new Update());
}

class Update implements Runnable {
public void run() {
if(progress.isCanceled()) {
progress.close();
System.exit(1);
}
if(count ==0){
timer.stop();
}
progress.setProgress(count);
progress.setNote("Operation left " + TIME.format(new Date(count-- * 1000)) + "");
System.out.println(TIME.format(new Date(count-- * 1000)));
--count;
}
}
}
---------------------------------------------

Read for more information.

http://www.roseindia.net/java/example/java/swing/

Thanks.









Related Tutorials/Questions & Answers:
j2me timer and timer task
j2me timer and timer task  have anyone idea to change a direction of bubble, according to changing time.   Please go through the following links: http://www.roseindia.net/j2me/timer-midlet.shtml http
Timer and TimerTask
Timer and TimerTask  i have problem of java.lang.IllegalStateException: Task already scheduled or cancelled
Advertisements
Java timer
Java timer  Hi. I want to use a timer in one of my java projects... java.util.Timer; import java.util.TimerTask; public class ToDo { Timer timer;ADS_TO_REPLACE_1 public ToDo ( int seconds ) { timer = new Timer
timer using javascript
timer using javascript  How to display timer on HTML page using JavaScript
ModuleNotFoundError: No module named 'timer'
ModuleNotFoundError: No module named 'timer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'timer' How to remove the ModuleNotFoundError: No module named 'timer'
Difference between Timer and Thread?
Difference between Timer and Thread?  Can anyone tell me about the difference between Timer and Thread, Why we need to have Timer in case we have Thread implimentation startegy in Java
Java Timer Task
Java Timer Task  How to assign a task in java at specified date & time (with seconds) using threads
code for timer in java netbeans for online test series countdown timer
code for timer in java netbeans for online test series countdown timer  code for timer in java netbeans for online test series countdown timer
Insertion Sort Timer
Insertion Sort Timer  Welcome all I wanna program in java find the timer of insertion sort and find time complexity for random value thanks all
Timer - Swing AWT
Timer  How can I make a simple countdown timer in my GUI?  ... { ProgressMonitor progress; static int counter = 0; Timer timer...("Progress bar timer Demo"); setSize(250, 100); setDefaultCloseOperation
Version of com.ineunet>knife-timer dependency
List of Version of com.ineunet>knife-timer dependency
Version of geronimo>geronimo-timer dependency
List of Version of geronimo>geronimo-timer dependency
Version of com.rhcloud>timemanager-timer dependency
List of Version of com.rhcloud>timemanager-timer dependency
javascript timer countdown
javascript timer countdown  How to disable/enable the javascript timer countdown?   <!-- CSS Code --> #txt { border:none; font... = "yourpage.htm" // redirects to specified page once timer ends and ok button
ModuleNotFoundError: No module named 'code-timer'
ModuleNotFoundError: No module named 'code-timer'  Hi, My Python... 'code-timer' How to remove the ModuleNotFoundError: No module named 'code-timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'django-timer'
ModuleNotFoundError: No module named 'django-timer'  Hi, My Python... 'django-timer' How to remove the ModuleNotFoundError: No module named 'django-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'easy-timer'
ModuleNotFoundError: No module named 'easy-timer'  Hi, My Python... 'easy-timer' How to remove the ModuleNotFoundError: No module named 'easy-timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'maple_timer'
ModuleNotFoundError: No module named 'maple_timer'  Hi, My Python... 'maple_timer' How to remove the ModuleNotFoundError: No module named 'maple_timer' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'nose-timer'
ModuleNotFoundError: No module named 'nose-timer'  Hi, My Python... 'nose-timer' How to remove the ModuleNotFoundError: No module named 'nose-timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'pomodoro-timer'
ModuleNotFoundError: No module named 'pomodoro-timer'  Hi, My... named 'pomodoro-timer' How to remove the ModuleNotFoundError: No module named 'pomodoro-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'progress-timer'
ModuleNotFoundError: No module named 'progress-timer'  Hi, My... named 'progress-timer' How to remove the ModuleNotFoundError: No module named 'progress-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'python-timer'
ModuleNotFoundError: No module named 'python-timer'  Hi, My Python... 'python-timer' How to remove the ModuleNotFoundError: No module named 'python-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'relative-timer'
ModuleNotFoundError: No module named 'relative-timer'  Hi, My... named 'relative-timer' How to remove the ModuleNotFoundError: No module named 'relative-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'run-timer'
ModuleNotFoundError: No module named 'run-timer'  Hi, My Python... 'run-timer' How to remove the ModuleNotFoundError: No module named 'run-timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'simple_timer'
ModuleNotFoundError: No module named 'simple_timer'  Hi, My Python... 'simple_timer' How to remove the ModuleNotFoundError: No module named 'simple_timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'srt-timer'
ModuleNotFoundError: No module named 'srt-timer'  Hi, My Python... 'srt-timer' How to remove the ModuleNotFoundError: No module named 'srt-timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'timer-lawn'
ModuleNotFoundError: No module named 'timer-lawn'  Hi, My Python... 'timer-lawn' How to remove the ModuleNotFoundError: No module named 'timer-lawn' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'tmux-timer'
ModuleNotFoundError: No module named 'tmux-timer'  Hi, My Python... 'tmux-timer' How to remove the ModuleNotFoundError: No module named 'tmux-timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'code-timer'
ModuleNotFoundError: No module named 'code-timer'  Hi, My Python... 'code-timer' How to remove the ModuleNotFoundError: No module named 'code-timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'easy-timer'
ModuleNotFoundError: No module named 'easy-timer'  Hi, My Python... 'easy-timer' How to remove the ModuleNotFoundError: No module named 'easy-timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'gevent_timer'
ModuleNotFoundError: No module named 'gevent_timer'  Hi, My Python... 'gevent_timer' How to remove the ModuleNotFoundError: No module named 'gevent_timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'code-timer'
ModuleNotFoundError: No module named 'code-timer'  Hi, My Python... 'code-timer' How to remove the ModuleNotFoundError: No module named 'code-timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'djangocms-timer'
ModuleNotFoundError: No module named 'djangocms-timer'  Hi, My... named 'djangocms-timer' How to remove the ModuleNotFoundError: No module named 'djangocms-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-timer'
ModuleNotFoundError: No module named 'django-timer'  Hi, My Python... 'django-timer' How to remove the ModuleNotFoundError: No module named 'django-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'easy-timer'
ModuleNotFoundError: No module named 'easy-timer'  Hi, My Python... 'easy-timer' How to remove the ModuleNotFoundError: No module named 'easy-timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'gevent_timer'
ModuleNotFoundError: No module named 'gevent_timer'  Hi, My Python... 'gevent_timer' How to remove the ModuleNotFoundError: No module named 'gevent_timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'magic-timer'
ModuleNotFoundError: No module named 'magic-timer'  Hi, My Python... 'magic-timer' How to remove the ModuleNotFoundError: No module named 'magic-timer' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'monocle_timer'
ModuleNotFoundError: No module named 'monocle_timer'  Hi, My... 'monocle_timer' How to remove the ModuleNotFoundError: No module named 'monocle_timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'noop-timer'
ModuleNotFoundError: No module named 'noop-timer'  Hi, My Python... 'noop-timer' How to remove the ModuleNotFoundError: No module named 'noop-timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'osimis-timer'
ModuleNotFoundError: No module named 'osimis-timer'  Hi, My Python... 'osimis-timer' How to remove the ModuleNotFoundError: No module named 'osimis-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'perf-timer'
ModuleNotFoundError: No module named 'perf-timer'  Hi, My Python... 'perf-timer' How to remove the ModuleNotFoundError: No module named 'perf-timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'pref_timer'
ModuleNotFoundError: No module named 'pref_timer'  Hi, My Python... 'pref_timer' How to remove the ModuleNotFoundError: No module named 'pref_timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'process-timer'
ModuleNotFoundError: No module named 'process-timer'  Hi, My... 'process-timer' How to remove the ModuleNotFoundError: No module named 'process-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyprof-timer'
ModuleNotFoundError: No module named 'pyprof-timer'  Hi, My Python... 'pyprof-timer' How to remove the ModuleNotFoundError: No module named 'pyprof-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pytest-timer'
ModuleNotFoundError: No module named 'pytest-timer'  Hi, My Python... 'pytest-timer' How to remove the ModuleNotFoundError: No module named 'pytest-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'python-timer'
ModuleNotFoundError: No module named 'python-timer'  Hi, My Python... 'python-timer' How to remove the ModuleNotFoundError: No module named 'python-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'py-timer'
ModuleNotFoundError: No module named 'py-timer'  Hi, My Python...-timer' How to remove the ModuleNotFoundError: No module named 'py-timer... to install padas library. You can install py-timer python with following
ModuleNotFoundError: No module named 'robotframework-timer'
ModuleNotFoundError: No module named 'robotframework-timer'  Hi...: No module named 'robotframework-timer' How to remove the ModuleNotFoundError: No module named 'robotframework-timer' error? Thanks   Hi
ModuleNotFoundError: No module named 'run-timer'
ModuleNotFoundError: No module named 'run-timer'  Hi, My Python... 'run-timer' How to remove the ModuleNotFoundError: No module named 'run-timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'sal-timer'
ModuleNotFoundError: No module named 'sal-timer'  Hi, My Python... 'sal-timer' How to remove the ModuleNotFoundError: No module named 'sal-timer' error? Thanks   Hi, In your python environment you

Ads