AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Timer as an inner class

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
raam
Guest





PostPosted: Thu Mar 30, 2006 2:12 pm    Post subject: Timer as an inner class Reply with quote



Hi all,
I am trying to use a timer to make a label blink in a frame.I am adding
a class inside the frame for this purpose.But whe i compile it says '
<identifier > expected at the line

timer.schedule( <-here task,period);
I hve given the code below.Can anyone please help.
Raam

Code:

class Tmier {
int delay = 5000; // delay for 5 sec.
int period = 1000; // repeat every sec.
java.util.Timer timer = new java.util.Timer();
class task extends TimerTask{
public void run() {
if(LQ.getForeground().equals(Color.RED))
LQ.setForeground(LQ.getBackground());
else
LQ.setForeground(Color.RED);

repaint();
}
}
timer.schedule(task,period);
}//Inner class Timer
Back to top
Allan M. Bruce
Guest





PostPosted: Thu Mar 30, 2006 2:12 pm    Post subject: Re: Timer as an inner class Reply with quote



"raam" <muthuramantripura (AT) gmail (DOT) com> wrote in message
news:1143725960.805662.128380 (AT) u72g2000cwu (DOT) googlegroups.com...
Quote:
Hi all,
I am trying to use a timer to make a label blink in a frame.I am adding
a class inside the frame for this purpose.But whe i compile it says '
identifier > expected at the line

timer.schedule( <-here task,period);
I hve given the code below.Can anyone please help.
Raam

Code:

class Tmier {
int delay = 5000; // delay for 5 sec.
int period = 1000; // repeat every sec.
java.util.Timer timer = new java.util.Timer();
class task extends TimerTask{
public void run() {
if(LQ.getForeground().equals(Color.RED))
LQ.setForeground(LQ.getBackground());
else
LQ.setForeground(Color.RED);

repaint();
}
}
timer.schedule(task,period);
}//Inner class Timer


I suggest using something like this instead:

javax.swing.Timer myTimer = new javax.swing.Timer(period, new
ActionListener()
{
public void actionPerformed(ActionEvent xiEvent)
{
// do your things in here
}
});
myTimer.setInitialDelay(delay);
myTimer.start();


HTH
Allan
Back to top
raam
Guest





PostPosted: Thu Mar 30, 2006 2:12 pm    Post subject: Re: Timer as an inner class Reply with quote



Hi all ,
I made a silly mistake in the program and posted a question.Sorry .
Raam.
Back to top
raam
Guest





PostPosted: Thu Mar 30, 2006 3:12 pm    Post subject: Re: Timer as an inner class Reply with quote

Thank you sir
Back to top
Chris Smith
Guest





PostPosted: Mon Apr 03, 2006 12:12 am    Post subject: Re: Timer as an inner class Reply with quote

Allan M. Bruce <allanmb (AT) TAKEAWAYdsl (DOT) pipex.com> wrote:
Quote:
I suggest using something like this instead:

javax.swing.Timer myTimer = new javax.swing.Timer(period, new
ActionListener()
{
public void actionPerformed(ActionEvent xiEvent)
{
// do your things in here
}
});
myTimer.setInitialDelay(delay);
myTimer.start();

To expand upon that for posterity's sake, the reason that a
javax.swing.Timer is preferred here is that event notifications will
then be delivered in the AWT event dispatch thread. If LQ is a GUI
component, then the result of modifying its properties from an arbitrary
thread after it is displayed on the screen are undefined. The necessary
threading could also have been achieved by using EventQueue.invokeLater
from a TimerTask with java.util.Timer, but it would have been a pain and
more difficult to read.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.