📄 clocktime.java
字号:
////////////////////////////////////////////////////// Time Display Applet V1.00//// KAC Website Design - http://www.kacweb.com//// Created 4/4/97 by Kenny A. Chaffin//// Last Updated 4/8/97 by Kenny A. Chaffin///////////////////////////////////////////////////// Standard Java Importsimport java.applet.*;import java.awt.*;import java.net.*;import java.util.*;import java.io.*;public class ClockTime extends java.applet.Applet implements Runnable { private volatile Thread clock; private String font_name, title, datestring, timestring; // name of the font private int height, width, font_size; // font size (points) private Font wordFont; private FontMetrics wordMetrics; private int textcolor, backcolor, bordercolor; private int stringx, stringy; private int delay; private Image off_image; private Graphics offg; TimeAndDateFormatter formattedTimeAndDate; public void init() { String temp; timestring = ""; Dimension appletSize = this.getSize(); height = appletSize.height; width = appletSize.width; off_image = createImage(width, height); offg = off_image.getGraphics(); // get the name and size of the font temp = getParameter("delay"); delay= (temp==null) ? 5000 : Integer.parseInt( temp ); temp=getParameter("title"); title = (temp==null) ? " " : temp; temp=getParameter("font"); font_name= (temp==null) ? "TimesRoman" : temp; temp = getParameter("fontsize"); font_size= (temp==null) ? 12 : Integer.parseInt( temp ); // initialise the font wordFont = new Font(font_name, Font.PLAIN, font_size); if (wordFont == null) wordFont = getFont(); wordMetrics = getFontMetrics (wordFont); temp = getParameter("textcolor"); textcolor = (temp==null) ? 0x000000 : Integer.parseInt(temp, 16); temp = getParameter("backcolor"); backcolor= (temp==null) ? 0xffffff : Integer.parseInt(temp, 16); temp = getParameter("bordercolor"); bordercolor = (temp==null) ? backcolor : Integer.parseInt(temp, 16); } public void start() { clock = new Thread(this); // start the thread clock.start(); } public void stop() { clock = null; } public void run() { Thread thisThread = Thread.currentThread(); thisThread.setPriority(Thread.MIN_PRIORITY); while(clock == thisThread) { Date date = new Date(); formattedTimeAndDate = new TimeAndDateFormatter( date, title ); datestring = formattedTimeAndDate.dateToString(); timestring = formattedTimeAndDate.timeToString(); timestring = datestring + ", " + timestring; repaint(); try { thisThread.sleep(delay); } catch( InterruptedException e ) {} } } public void update (Graphics g) { paint(g); } public synchronized void paint(Graphics g) { offg.setFont(wordFont); // set the font in the graphics context offg.setColor(new Color(backcolor)); // fill area with the background color offg.fillRect(0,0,width,height); offg.setColor(new Color(textcolor)); stringy = (height - (wordMetrics.getHeight()-wordMetrics.getLeading()))/2 + (wordMetrics.getHeight()-wordMetrics.getLeading()-wordMetrics.getDescent()); stringx = 1; offg.drawString (timestring, stringx, stringy); offg.setColor(new Color(bordercolor)); g.drawImage(off_image, 0, 0, this); } public void paintApplet(Graphics g) { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -