File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Threads and Synchronization
Author
Timer inside a Thread is not working!
Yohan Weerasinghe
Ranch Hand
Joined: Oct 07, 2010
Posts: 484
I like...
posted
Mar 26, 2011 08:38:55
0
Hello all,
Here I am trying to execute a timer inside a thread. But that is not working. Here is my code
import javax.swing.*; import java.awt.*; import java.util.*; import java.text.*; import javax.swing.Timer; import java.awt.event.*; public class JustCheck extends JFrame { JLabel label1; Timer timer1=null; forTime f = new forTime(); public JustCheck() { label1 = new JLabel(""); timer1 = new Timer(1000,f); timer1.start(); JPanel panel1 = (JPanel)getContentPane(); panel1.setLayout(new FlowLayout()); panel1.add(label1); } class forTime extends Thread implements ActionListener { public void actionPerformed(ActionEvent ae) { this.start(); } public void run() { Date date1 = new Date(); SimpleDateFormat format1 = new SimpleDateFormat("HH:mm:ss"); String out = format1.format(date1); label1.setText(out); } } public static void main(String[]args) { JustCheck j = new JustCheck(); j.setVisible(true); j.validate(); j.setSize(150,150); } }
Please help
Are you better than me? Then please show me my mistakes..
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4163
3
I like...
posted
Mar 26, 2011 09:10:11
0
Please
CarefullyChooseOneForum
. I'm locking this thread.
luck, db
There are no new questions, but there may be new answers.
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Timer inside a Thread is not working!
Similar Threads
Java: Display Time
JFrame/JPanel problem
Blank Frame or Panel
Error in FileReader
Help with ActionListener
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter