|
Threads Beispiel: import java.awt.*; import java.util.*; public class Zeit01 extends java.applet.Applet implements Runnable { Font theFont = new Font("TimesRoman",Font.BOLD,24); GregorianCalendar theDate; Thread runner; public void start() { if(runner==null) { runner=new Thread(this); runner.start(); } } public void stop() { if(runner!=null) { runner.stop(); runner=null; } } public void run() {
while(true)
{
repaint();
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
System.out.println(e);
}
}
}
public void paint(Graphics g)
{
theDate=new GregorianCalendar();
g.setFont(theFont);
g.drawString(" " + theDate.getTime(), 10, 50);
}
}
|
|
|