Write applet applets that display the current system time in different colors and fonts by receiving parameters in an HTML document.
Import java.awt.*;
Import Java.applet.Applet;
Import java.util.*;
Import Java.awt.Graphics; The public class clock extends applet implements Runnable//inherits the applet class and implements the Runnable interface {thread clockthread=null;//Create an empty threads C
Alendar now;
Private String S1;
private int size;
int r1,g1,b1;
public void init ()//initialization method {Size=integer.parseint (GetParameter ("size"));//Get font size} public void Start () {
if (clockthread==null) {clockthread=new thread (this, "Clock2");//Create Thread Object Clockthread clockthread.start ();//Start thread execution } The public void Run ()//Implement the Run () method of the Runnable interface {thread mythread=thread.currentthread ();//Create the Threading object Mythread whi Le (clockthread==mythread) {repaint ()//Call paint method try {thread.sleep (1000) by repaint method;//Hibernate 1 sec} catch (in Terruptedexception e) {}}} public void Paint (Graphics g) {r1= (int) (Math.random () *255);//By calling the Math class's Rando M produces random number g1= (int) (Math.random () *255);
Then the three primary colors were set by random number, red-green-blue b1= (int) (Math.random () *255); CoLor c=new Color (R1,G1,B1); Create a Color object G.setcolor (c); Set color now=calendar.getinstance (); Gets the system current time S1=now.get (now. HOUR) + "Time" +now.get (now. MINUTE) + "min" +now.get (now.
SECOND) + "seconds"; Font f=new font ("", 1,size);
Sets the font g.setfont (f); g.DrawString (s1,10,50);
Displays the string for the specified size color} public void Stop ()//Call stop method, stop thread {clockthread=null; } <pre class= "html" name= "code" >
This is how to use the thread to realize the dynamic display of the system time, I hope to help you learn.