I just wanted to post an example on using Threads in Java.

most important things are ...
(1) making a class that extends the Thread class and implements the Runnable interface.
(2) add the run method to that class and put your functionallity in it
(3) make an instance of your class and set priority of that instance on low.
(4) start and stop the instance.

Enjoy.

Code:
import java.awt.*;
import javax.swing.*;

public class ExampleWindow extends JFrame{
    int Frames_Per_Second = 45;
    autoRefresh engine = new autoRefresh(Frames_Per_Second);

    public static void main(String args[]) {
        (new ExampleWindow()).show();
    }

    public ExampleWindow() {
        speelveld.setPreferredSize(new Dimension(500,500));
        getContentPane().setLayout(new java.awt.FlowLayout());
        pack();
        
        //constant refreshing
        engine.setPriority(Thread.MIN_PRIORITY);
        engine.start();
        
        //closing the window
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                engine.stop();
                System.exit(0);
            }
        });
    }
    
    class autoRefresh extends Thread implements Runnable{
        int ms_stop = 0;

        public autoRefresh(int fps){
            ms_stop = 1000 / fps;
        }

        public void run(){
            while (true){
                /*
                .... Add functionality here ...
                I use it for repainting my supermario game
                */
                waiting(ms_stop);
            }
        }
        
        private void waiting(long ms){
            long thetime = System.currentTimeMillis();
            boolean blnrepeat;
            while (blnrepeat){
                blnrepeat = (thetime + ms) > System.currentTimeMillis();
            }
        }
    }