158 lines
3.8 KiB
Java
Executable File
158 lines
3.8 KiB
Java
Executable File
//
|
|
// Copyright (c) 1995 Elf M. Sternberg.
|
|
//
|
|
// PendorClock.java v1.0 - Displays the time on Pendor in an applet
|
|
// by Elf Sternberg (elf@halcyon.com)
|
|
//
|
|
// Based in part on code by Chris Southern (southern@wsrn.com)
|
|
//
|
|
|
|
import java.awt.*;
|
|
import java.util.*;
|
|
import java.lang.*;
|
|
import java.applet.*;
|
|
|
|
public class PendorDate extends Applet implements Runnable {
|
|
Thread clock; // applet thread
|
|
Font font; // display font
|
|
|
|
Color bgColor; // applet bgcolor
|
|
Color fgColor; // applet fgcolor
|
|
|
|
Boolean bgColorSet = Boolean.FALSE; // bgColor set?
|
|
Boolean dateDisplay = Boolean.TRUE;
|
|
|
|
public void init() {
|
|
|
|
String FontName = getParameter("font");
|
|
if ( FontName == null ) FontName = "Times";
|
|
|
|
String FontSize = getParameter("size");
|
|
if ( FontSize == null) FontSize = "18";
|
|
|
|
int size = Integer.valueOf(FontSize).intValue();
|
|
|
|
String background = getParameter( "bgcolor" );
|
|
if (( background == null ) ||
|
|
( background.charAt(0) != '#' ) ||
|
|
( background.length() != 7 )) {
|
|
} else {
|
|
Integer rgbValue = new Integer(0);
|
|
rgbValue = Integer.valueOf( background.substring(1,7), 16 );
|
|
bgColor = new Color(rgbValue.intValue());
|
|
bgColorSet = Boolean.TRUE;
|
|
}
|
|
|
|
String foreground = getParameter( "fgcolor" );
|
|
if (( foreground == null ) ||
|
|
( foreground.charAt(0) != '#' ) ||
|
|
( foreground.length() != 7 )) {
|
|
fgColor = Color.black;
|
|
} else {
|
|
Integer rgbValue = new Integer(0);
|
|
rgbValue = Integer.valueOf( foreground.substring(1,7), 16 );
|
|
fgColor = new Color(rgbValue.intValue());
|
|
}
|
|
|
|
// Setup Applet
|
|
font = new Font(FontName, Font.PLAIN, size );
|
|
}
|
|
|
|
private static short aiMonths[] = {
|
|
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
|
|
|
|
private static short aiPMonths[] = {
|
|
0, 1, 25, 49, 73, 97, 121, 145, 146, 147, 171, 195, 211, 243, 267, 291, 292 };
|
|
|
|
private static String asMNames[] = {
|
|
"Yestar", "Narrin", "Nenim", "Sulim", "Virta", "Lothess",
|
|
"Narnya", "Attendes", "Loende", "Cerim", "Urim", "Yavar",
|
|
"Narquel", "Hiss", "Ring", "Mettare" };
|
|
|
|
private static String asWNames[] = {
|
|
"Seren", "Anar", "Noren", "Aldea", "Erwer", "Elenya" };
|
|
|
|
// paint - display the clock, and process am & pm stuff
|
|
|
|
public void paint( Graphics g ) {
|
|
Date d = new Date();
|
|
String strOut = new String();
|
|
|
|
int iDay, iYer, iYday, iHour, iSec, iMin, i;
|
|
|
|
iDay = aiMonths[d.getMonth()] + d.getDate();
|
|
|
|
|
|
if (d.getMonth() > 2 )
|
|
if (d.getYear() % 4 == 0)
|
|
if (d.getYear() % 2000 != 0)
|
|
iDay++;
|
|
|
|
// Leap Year/GMT patch. Ick.
|
|
iDay = (iDay * 24) + d.getHours() - 16;
|
|
iYer = d.getYear() + 16;
|
|
|
|
iYday = iDay / 30;
|
|
iHour = iDay % 30;
|
|
|
|
iSec = (int) ((d.getSeconds() + (d.getMinutes() * 60)) / 2.25);
|
|
|
|
iMin = iSec / 40;
|
|
iSec = iSec % 40;
|
|
|
|
|
|
Dimension appletSize = size();
|
|
|
|
g.setFont( font );
|
|
|
|
if ( bgColorSet == Boolean.TRUE ) {
|
|
g.setColor( bgColor );
|
|
g.fillRect( 0, 0, appletSize.width, appletSize.height );
|
|
}
|
|
g.setColor( fgColor );
|
|
|
|
strOut = "The time on Pendor is " + String.valueOf(iHour) + ":";
|
|
|
|
if (iMin < 10)
|
|
strOut = strOut + "0";
|
|
|
|
strOut = strOut + String.valueOf(iMin) + ":";
|
|
|
|
if (iSec < 10)
|
|
strOut = strOut + "0";
|
|
|
|
strOut = strOut + String.valueOf(iSec);
|
|
|
|
for(i = 0; i <= 17; i++)
|
|
if (aiPMonths[i] >= iYday)
|
|
break;
|
|
|
|
strOut = strOut + " on " + asWNames[(i - 1) % 6] + ", " + asMNames[(i-1)] + " " +
|
|
String.valueOf(iYday - aiPMonths[i - 1]) + ", 0" + String.valueOf(iYer);
|
|
|
|
g.drawString(strOut, 2, font.getSize() );
|
|
}
|
|
|
|
// start - start the applet
|
|
public void start() {
|
|
clock = new Thread( this );
|
|
clock.start();
|
|
}
|
|
|
|
// stop - stop the applet
|
|
public void stop() {
|
|
clock.stop();
|
|
}
|
|
|
|
// run - main
|
|
public void run() {
|
|
while (true) {
|
|
try {
|
|
Thread.sleep(1250);
|
|
}
|
|
catch (InterruptedException e) {}
|
|
repaint();
|
|
}
|
|
}
|
|
}
|