import javax.swing.*; 
import java.awt.*; 
import java.util.Date;
class ThreadFrame extends JFrame
{	private boolean b = true;
	private Date  miaData = new Date(); 
	private Font f = new Font("Arial", Font.BOLD, 16);
	private Object o = new Object();
	class ClaThread extends Thread
	{	public void run()
		{	while (b) 
			{	synchronized(o) // prelievo della data
				{	miaData = new Date();	}
				repaint();
				try	{	mioThread.sleep(500);	}
				catch (InterruptedException e) { }
			}
		}
	}
	private ClaThread mioThread = new ClaThread();
	class MioPanel extends JPanel
	{	public MioPanel()
		{	setBackground(Color.yellow);	}
		public void paintComponent(Graphics g)
		{	super.paintComponent(g); g.setFont(f); 
			synchronized (o)	// visualizzazione della data
			{	g.drawString(miaData.toString(), 30, 60);	}
		}
	}
	private MioPanel p = new MioPanel();
	ThreadFrame()
	{	setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		getContentPane().add(p);
	}
	void inizio()
	{	mioThread.start();	}
	void fine()
	{	b = false;	}
}

public class Prova
{	public static void main(String[] args)
	{	ThreadFrame ft = new ThreadFrame();
		ft.setSize(300, 150);
		ft.setVisible(true);
		ft.inizio();
		try { Thread.sleep(50000); }
		catch(InterruptedException e) {}
		ft.fine();
	}
}
