Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Jhen
Timer
1 Answer(s)      6 years ago
Posted in : Swing AWT



Advertisement
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; 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
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
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
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
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
Registration timer expired, but client is still registering!
Registration timer expired, but client is still registering!  Registration timer expired, but client is still registering
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
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
J2ME Timer Animation
J2ME Timer Animation       This application illustrates how to use the Timer class..., which helps you to understand using of timer class for drawing the canvas
Scheduling a Timer Task
Scheduling a Timer Task       In this section, you can learn how to schedule a timer task to run... the timer task at a certain time means the task will work only once while you
Please tell me how can i convert string to timer
Please tell me how can i convert string to timer  Please tell me how can i convert string to timer
php
php using javasript  how to set timer in php using javasript
anurag
anurag  how to get displaying div using jquery timer. at every 10sec one div display
stopwatch
stopwatch  Java code for stopwatch timer which should start from zero
Hacking
Hacking  hi friends.. can any one tell how to hack the ip address using java coding and i need to add timer in frame .. then i want to compare timer value ...pls help me asap.. i ll thank full
JSP - JSP-Servlet
JSP  Hi! I want example of Timer class. That means the class has to raise an alert message at the given time by the user. Thanks in advance
Comparison between the types of sorting in java
In terms of timer and put all types in frame and find the timer for example array 0-10000 the program select random value and it found timer for all types
scheduledTimerWithTimeInterval Example
object telling it to when to fire a timer or update it in a certain time intervals. And "scheduledTimerWithTimeInterval" schedules the timer...:userInfo:repeats: that basically creates the timer and schedules
Advertisements
 

 

 

DMCA.com