/* mars.java - Display the 'time' on Mars Copyright (C) 1997, 2003 Frank Sorenson (frank@byu.net) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import java.awt.*; import java.applet.Applet; import java.io.*; import java.net.*; import java.util.*; import java.lang.*; public class mars extends Applet implements Runnable { Thread MyThread = null; int MyDelay; int FGValue; int BGValue; public static void main (String [] args) { System.out.println("Content-type: text/html\n"); System.out.println("

Hello world

"); } int GetNumberParam(String ValueString, int DefaultValue) { Integer TempInt; String TempString; TempString = getParameter(ValueString).toUpperCase(); if (TempString.startsWith("0X")) { int i; int TempInt2; TempInt2 = 0; for (i = 2 ; i < ValueString.length() ; i ++) { TempInt2 = (TempInt2 + (new String("0123456789ABCDEF")).indexOf(TempString.charAt(i))) * 16; } return(TempInt2); } try { TempInt = Integer.valueOf(TempString); } catch (NumberFormatException z) { return DefaultValue; } return TempInt.intValue(); } public void init() { FGValue = GetNumberParam("FGColor", 0x000000); BGValue = GetNumberParam("BGColor", 0xFFFFFF); MyDelay = GetNumberParam("Delay", 973); setForeground(new Color(FGValue)); setBackground(new Color(BGValue)); setFont(new Font("Courier",Font.BOLD,14)); System.out.println("This Applet by Frank Sorenson (frank AT tuxrocks.com)"); System.out.println("http://www.tuxrocks.com/Projects/mars/"); } public void start() { if ( MyThread == null ) { MyThread = new Thread(this); MyThread.start(); } } public void run() { while ( MyThread != null ) { try { MyThread.sleep(MyDelay); } catch (InterruptedException e) { break; } this.resize(400, 120); this.repaint(); while (true) { try { MyThread.sleep(MyDelay); } catch (InterruptedException e) { } this.repaint(); } } } public void stop() { MyThread.stop(); MyThread = null; } public boolean mouseEnter(java.awt.Event evt, int x, int y) { showStatus("(c) 1997 Frank Sorenson"); return (true); } public boolean mouseDown(java.awt.Event evt, int x, int y) { // MyThread.resume(); return (true); } public String FormatLong(long InVal) { if (InVal > 9) return("" + InVal); return("0" + InVal); } public void paint(Graphics graph) { Date dat = new Date(); String OutputString; long CurrentTime; long TempTime; int TempInt; float TempFloat; CurrentTime = dat.getTime(); TempTime = CurrentTime - (dat.getTimezoneOffset() * 60000); OutputString = "EarthTime: "; //Day "; TempTime = TempTime % 86400000; OutputString += " " + FormatLong(TempTime / 3600000) + ":"; TempTime = TempTime % 3600000; OutputString += FormatLong(TempTime / 60000) + ":"; TempTime = TempTime % 60000; OutputString += FormatLong(TempTime / 1000); graph.drawString(OutputString, 10, 10); // 1 Mars second = 1.0275 Earth seconds // 1 Mars minute = 1 Earth minute, 1.65 Earth seconds // 1 Mars hour = 1 Earth hour, 1 Earth minute, 39 Earth seconds TempTime = CurrentTime - dat.parse("Mon 21 Jul, 1997 12:00:00 GMT"); TempFloat = (float)TempTime; TempFloat /= 1.027382246883; TempTime = (long)TempFloat; TempTime += 40648000; // Add the seconds the above date TempTime += 17*(86400000); // Add 17 extra days OutputString = "MarsTime: Sol "; OutputString += TempTime / 86400000; TempTime = TempTime % 86400000; OutputString += " " + FormatLong(TempTime / 3600000) + ":"; TempTime = TempTime % 3600000; OutputString += FormatLong(TempTime / 60000) + ":"; TempTime = TempTime % 60000; OutputString += FormatLong(TempTime / 1000); graph.drawString(OutputString, 10, 50); OutputString = "This Applet by Frank Sorenson (sorenson@byu.edu)"; graph.drawString(OutputString, 10, 90); OutputString = "http://pel.cs.byu.edu/~sorenson/"; graph.drawString(OutputString, 10, 110); return; } }