Re: Timer as an inner class




"raam" <muthuramantripura@xxxxxxxxx> wrote in message
news:1143725960.805662.128380@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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


.



Relevant Pages

  • Re: Animating auto hide of JPanel inside a JFrame
    ... When the mouse is brought close to the top of the panel, a label 'slides' down ... public void actionPerformed ... private void positionLabel ... Timer class that is called back at intervals. ...
    (comp.lang.java.gui)
  • Re: Change status bar text back to default 5 seconds after every change?
    ... private Timer timeReset = new Timer; ... public void OnTimerTick ... that I can't use the StatusBar's OnChange event (or ...
    (microsoft.public.dotnet.languages.csharp)
  • Panels on a BorderLayout
    ... I have just finished this application that draws a rectangle inside a panel & uses a thread or a timer to animate it. ... int size = 0; ... public void setSize{ ...
    (comp.lang.java.help)
  • Re: Need time waster code or something.
    ... timer to try to solve my current problem. ... public void flashButton() ... public class buttonFlash ... Toolkit toolkit; ...
    (comp.lang.java.gui)
  • Deleting ones self from a Dictionary
    ... Assuming a class contains an event handler (say from a timer), ... public void CreateBar(string ID) ...
    (microsoft.public.dotnet.languages.csharp)