Timer

Ads

 
 

Share on Google+Share on Google+

Jhen
Timer
1 Answer(s)      8 years ago
Posted in : Swing AWT
Ads
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.

Ads









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; public ToDo ( int seconds ) { timer = new Timer
timer using javascript
timer using javascript  How to display timer on HTML page using JavaScript
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
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
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
Countdown timer to show a link
Countdown timer to show a link  Hi to everyone! I have this code, which is basically a countdown widget...what I want is that when the countdown finish, a link appears. The thing is that my musical group will be presenting an EP
JavaScript Clock Timer
JavaScript Clock Timer...; In this section, we are going to show you a clock timer using JavaScript... than 9, then it will add 0 in front of min, sec or hour value like 09 in the timer
Timer in the code - Java Beginners
Timer in the code  This is the question I posted yesterday: "I'm trying to write a program that has a text field for input, two buttons and the output text area. A user is asked to type in a number. The first button when pressed
Registration timer expired, but client is still registering!
Registration timer expired, but client is still registering!  Registration timer expired, but client is still registering
ServletContextListener with Timer
In this section, you will learn how to use timer with ServletContextListener to run code snippet after every 1 minute immediate after the application run
java hello and timer alert application
java hello and timer alert application  Hi, Please help me create a simple Java application that can display "Hello world" and current Time alert on mobile device screen using mobile screen emulator. Regards
Java + Timer concept - Java Beginners
Java + Timer concept  sir, I am using swing based model. My form... interval) and retrieve values and print it in console. I want code using timer... label; JProgressBar pb; Timer timer; JButton button; public
J2ME Timer MIDlet Example
J2ME Timer MIDlet Example       This Example shows how to use of timer class. In this example we are using the Timer class to create the time of execution  of application
Version of com.spikhalskiy>hashed-wheel-timer dependency
List of Version of com.spikhalskiy>hashed-wheel-timer dependency
Retrieval data from database against timer
Retrieval data from database against timer  Please send me a sample timer code which retrieve data from the database against timer in JSP
Maven Dependency geronimo-timer >> 1.0
You should include the dependency code given in this page to add Maven Dependency of geronimo >> geronimo-timer version1.0 in your project
Maven Dependency geronimo-timer >> 1.0-M2
You should include the dependency code given in this page to add Maven Dependency of geronimo >> geronimo-timer version1.0-M2 in your project
Maven Dependency geronimo-timer >> 1.0-M3
You should include the dependency code given in this page to add Maven Dependency of geronimo >> geronimo-timer version1.0-M3 in your project
Maven Dependency geronimo-timer >> 1.0-M4
You should include the dependency code given in this page to add Maven Dependency of geronimo >> geronimo-timer version1.0-M4 in your project
Maven Dependency geronimo-timer >> 1.0-M5
You should include the dependency code given in this page to add Maven Dependency of geronimo >> geronimo-timer version1.0-M5 in your project
Maven Dependency geronimo-timer >> 1.1
You should include the dependency code given in this page to add Maven Dependency of geronimo >> geronimo-timer version1.1 in your project
Maven Dependency geronimo-timer >> 1.1.1
You should include the dependency code given in this page to add Maven Dependency of geronimo >> geronimo-timer version1.1.1 in your project
Maven Dependency knife-timer >> 0.0.2
You should include the dependency code given in this page to add Maven Dependency of com.ineunet >> knife-timer version0.0.2 in your project