
Here is a piece of code to build a Java clock, that uses threads, gets the data for time automatically and is not interrupted if you click something else on the window. There are some comments around the code to help you understand what's happening.
import java.awt.*;
import javax.swing.*;
import java.util.*;
class Clock extends JFrame implements Runnable
{
Thread runner; //declare global objects
Font clockFont;
...