Timer implementation in swing
Hello ,I have searched but its a bit confusing on how a timer is used
I have an animated robot which needs to be moved and i'm doign this throuh a loop.
but i want to delay a single movement so its possible to see the animation
this is the small code where i want to implement the timer
Code:
Code Java:
public void moveRobot()
{
for (int i=0;i<=620;i+=31)
{
robot.setLocation(i, 10);
//Thread.sleep(1000);
}
for (int i=0;i<=500;i+=31)
{
robot.setLocation(500, i);
}
values are just for trial purpose but i wan to know how will i put a timer that every single loop is delayed by 1 seconds ?
thank you
Re: Timer implementation in swing
I'm not sure I understand your question, but I'd guess that you'd benefit from reading this: How to Use Swing Timers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features)
PS- That's the first hit I got when googling "swing timer".