A classic Java applet clock program (1)

xiaoxiao2021-03-06  41

It's going to pass over an eye, I have been one year old, and I am depressed. Taking advantage of a few minutes, I will send a few articles quickly and give it to the past year.

The program is discovered from the Internet and is a simple clock display program.

Code Features: Clock Code provides various interfaces, you can set, change colorful clock models in the HTML file, parameter instructions Info array

Drawing of the clock uses a dual buffer graphics processing mechanism, that is, draw a graphic in the buffer, and then display the graphic to the web page can effectively prevent flashing.

The continuous drawing of the clock is to constantly read the system time through a thread, and if the time is changed, it will be drawn. Use a thread to draw, a thread processing web page compares the applet setting specification.

Code section: import java.awt. *; Import java.applet. *; Import java.util. *; Import java.net. *;

Class HMS Extends Date {public HMS (Double Localoffset) {// If time zone is set in the HTML file, set the time to the local time zone time Super (); long tzoffset = getTimezoneOffset () * 60L * 1000L; localoffset * = 3600000.0; SetTime (getTime () TZOFFSET (long) locLoffset;

Public HMS () {// If there is no time zone, use the local time super ();

Public double get_hours () // Time conversion, convert such as 5:30 this time to 5.5 {return (double) superMinutes () (Double) getminutes () / 60.0;}}

Abstract class clockhand // Abstract class, a clocior needle, minute, second hand class, {protected int basex [], basey []; protected int transx [], transy []; protected int numberofpoint

Public Clockhand (int Originx, int originy, int point) {basex = new int [Points]; basey = new int [pointx = new int = new int = new int = InitiallizePoints (Originx, Originy, Length, Thickness); Numberofpoints = POINTS;}

Abstract protected void initiallizepoints (int Originx, Int Originy, int LENGTH, INTTIONICKESS);

Abstract Public Void Draw (Color Color, Double Angle, Graphics G);

Protected void transform (Double Angle) // Calculate the clock, minute, second hand drawn position {for (int i = 0; i

// Seconds use class class sweephand extends clockhand {public Sweephand (int Originx, int originy, int length, int point) {super (Originx, Originy, Length, 0, Points);

Protected Void InitiallizePoints (int Originx, int unimy, intlene) // initialization point {basex [0] = ORIGINX; Basey [0] = Originy; Basex [1] = Originx; Basey [1] = Originy-length / 5; Basex [2] = Originx; Basey [2] = Originy Length;}

Public Void Draw (Color Color, Double Angle, Graphics G) // Draw a second hand, for line segment {Transform (Angle); G.SetColor (color); g.drawline (Transx [1], Transy [1], Transx [2 ], TRANSY [2]);}}

Class Hmhand Extends ClockHand {Public Hmhand (int Originx, Int Originy, int LENGTH, INTTIONESS, INT POINTS) {Super (Originx, Originy, Length, Thickness, Points)

Protected void InitiallizePoints (int Originx, // Initial point int Originy, INT length, int thickness) {basex [0] = Originx; Basey [0] = Originy;

Basex [1] = basex [0] -Thickness / 2; Basey [1] = Basey [0] Thickness / 2;

Basex [2] = Basex [1]; Basey [2] = Basey [0] Length- thr ;x [3] = basex [0]; basey [3] = basey [0] length;

Basex [4] = Basex [0] thickness / 2; basey [4] = basey [2];

Basex [5] = Basex [4]; Basey [5] = Basey [1];

Public Void Draw (Color Color, Double Angle, Graphics G) // Draws a pitch for polygons {Transform (Angle); G.SetColor (Color); G.FillPolygon (Transx, Transy, NumberOfPoints);}}

The HMS class is a class clockHand, which is a time-converted class clockhand is the abstract base class of the pointer.

Subsequent part of the main function

转载请注明原文地址:https://www.9cbs.com/read-74209.html

New Post(0)