Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Auto Update

Posted on 2004-10-24
Medium Priority
Last Modified: 2010-03-31
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.
Question by:Shroder
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 92

Expert Comment

ID: 12397249
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)
LVL 92

Expert Comment

ID: 12397250
Another option would be to use the Timer class.

Expert Comment

ID: 12397455
I would go with what objects said since it does most of the threading work for you.
LVL 86

Accepted Solution

CEHJ earned 2000 total points
ID: 12398669
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()));
LVL 86

Expert Comment

ID: 12569967

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question