Auto Update

I am creating a java applet where it needs to show current data at x intervals. So I'm looking for a way to update the displayed data every 5 or 10 seconds. The data is displayed with both text and images. I have tried several things but seem to keep running into dead ends. I'm trying to find the best way to accomplish this. Any information or references would be appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Make you applet runnable and use a run() method something like the following:

public void run()
   while (running)
      // do what u need to do
   catch (Exception ex)
Another option would be to use the Timer class.
I would go with what objects said since it does most of the threading work for you.
If you're using Swing components in your applet, you should use a Swing Timer. Here's a clock example you can run:

<applet codebase="." code="ClockApplet.class" width="300" height="100">

import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ClockApplet extends JApplet implements ActionListener {
      Timer timer;
      Date currentTime;
      SimpleDateFormat timeFormat;
      JLabel labTime;

      public void init() {
            labTime = new JLabel();
            setLayout(new FlowLayout());
            currentTime = new Date();
            timeFormat = new SimpleDateFormat("HH:mm:ss");
            labTime.setText(timeFormat.format(new Date()));
            add(labTime, SwingConstants.CENTER);
            timer = new Timer(1000, this);

      public void actionPerformed(ActionEvent e) {
            labTime.setText(timeFormat.format(new Date()));

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.