As of:  Fri 2017-11-24 18:57:37 UTC  [=1511549857. 13:57:37-05:00]

>> SwatchTime.java  L: 10,255. A: 100444. M: 2002-03-27 16:29:25 UTC [=1017246565] -5721.10d >> 

// SwatchTime.java. Applet to display Swatch Internet time.
//
// You are free to use this code for non-commercial, educational
// purposes (I would appreciate appropriate credit...).  All other
// rights reserved.  Copyright 2000, Brad McCormick, Ed.D.

// Swimage.java is available at: http://www.cloud9.net/~bradmcc/SwImage.java

//Toolkit.getDefaultToolkit().beep();        // (The only available debugging tool....)

import java.applet.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import SwImage;    // ( http://www.cloud9.net/~bradmcc/SwImage.java )

/*
<title>TrivialApplet</title>
<hr><!-- needs SwatchTime1.gif and SwatchTime2.gif in ./gif subdirectory -->
<applet code="SwatchTime.class" width=327 height=28>
<param name=url value="http://www.swatch.com/">
</applet>
<hr>
<a href="TrivialApplet.java">The source.</a>
*/

public class SwatchTime extends Applet implements Runnable, MouseListener {

private final static String versionID                    = "3.6";
private final static boolean printDebuggingInformation   = false;

private Thread runner, runnerx;
private Font f;

private int tWidth = 327;         // Applet width
private int tHeight = 28;         // Applet height
private int tRate = 1000;

private boolean runnerRunning;
private Image buffered_image;
private Graphics gbuf;
private int char_ascent;
private int vAdj;
private Calendar nowGMT;
private Date now;
int tHeightX = -1;
String URLString = "http://www.swatch.com/";
private boolean runningRemote;


public void init() {
}

public void start() {

// This stuff used to be in init. Trying to get rid of NullPointerException / Security exception problems
    //nowGMT = new GregorianCalendar(TimeZone.getTimeZone("GMT+01"));    // Biel, Switzerland winter time,
                                                                      // but for some reason, in < JDK1.3,
                                                                      // this blows up the applet
    nowGMT = new GregorianCalendar(TimeZone.getTimeZone("GMT"));    
    try {
        String s = getParameter("url");
        if (s != null) {
            URLString = s;
        }
    } catch (Exception e) {
        printme("get Parameter failed");
    }
    runningRemote = getDocumentBase().getProtocol().equalsIgnoreCase("http");
    printme("runningRemote=" + runningRemote + ". URLString=" + URLString);    
    FontMetrics fm;
     
     
    buffered_image = createImage(tWidth, 3*tHeight);
    gbuf = buffered_image.getGraphics();
    printme("In start method: got gbuf");
    
    int fontSize = 10;                      // System dependent font size
    for (;;) {  
        f = new Font("Monospaced",Font.PLAIN,fontSize);
        gbuf.setFont(f);
        fm = gbuf.getFontMetrics(f);
        if (fm.stringWidth("000000") > 54) {
            break;
        }
        ++fontSize; 
    }
    f = new Font("Monospaced",Font.PLAIN,fontSize-1);
    gbuf.setFont(f);
    fm = gbuf.getFontMetrics(f);
    char_ascent = (((fm.getAscent() + fm.getLeading()) * 2) + 1) / 2;          // was +1 for rounding
    vAdj = (int)(tHeight / 2)  + (int)(char_ascent / 3);

    printme("fontSize=" + fontSize + ". fm.getAscent()=" + fm.getAscent() + ". fm.getLeading()=" +
                                                               fm.getLeading() + ".");
    printme("char_ascent=" + char_ascent + ". fm.stringWidth('000000')=" + fm.stringWidth("000000") + ".");
 
    gbuf.dispose();
    
    if (runningRemote) {
    //addMouseListener(new MyMouseListener());
        addMouseListener(this);
    } 
// End of stuff that used to be in init method

    if (runner == null) {
        boolean gotimage = false;
        gbuf = buffered_image.getGraphics();
        gbuf.setFont(f);
        
        SwImage image1 = new SwImage("SwatchTime1.gif");
        //SwImage image2 = new SmImage("SwatchTime2.gif");
        try {
            gbuf.drawImage(image1.getImage(), 0, tHeight, tWidth, tHeight, this);        // normal image is image1
            //gbuf.drawImage(image2.getImage(), 0, (2 * tHeight), tWidth, tHeight, this);  // mouseOver image is image2
        } catch (Exception e) {
            //printme("could not load image(s)");
            printme("could not load image1");
            gbuf.setColor(Color.white);
            gbuf.fillRect(0, tHeight, tWidth, tHeight);
            gbuf.setFont(new Font("Monospaced",Font.BOLD,fontSize-1));
            gbuf.setColor(Color.blue);
            gbuf.drawString("Swatch.beat: ", 18, tHeight + vAdj);
Toolkit.getDefaultToolkit().beep(); 
        }
        if (runningRemote) {
            SwImage image2 = new SwImage("SwatchTime2.gif");
            try {
                gbuf.drawImage(image2.getImage(), 0, (2 * tHeight), tWidth, tHeight, this);  // mouseOver image is image2
            } catch (Exception e) {
                //printme("could not load image(s)");
                printme("could not load image2");
                gbuf.setColor(Color.yellow);
                gbuf.fillRect(0, (2 * tHeight), tWidth, tHeight);
                gbuf.setFont(new Font("Monospaced",Font.BOLD,fontSize-1));
                gbuf.setColor(Color.red);
                gbuf.drawString("Swatch.beat: ", 18, (2 * tHeight) + vAdj);
Toolkit.getDefaultToolkit().beep();
            }
        }
    
        printme("Starting runner");    
 
        runnerRunning = true;
        runner = new Thread(this);
        runner.start();
    }
}


//**** Diagnostic info print method ************
static int lineNr = 0;
public static void printme(String s) {

    //**** Debugging switch ************
    if (!printDebuggingInformation) {
        return;
    }
    if (lineNr == 0) {
        System.out.println("\n0. SwatchTime.java verson: " + versionID + 
                             " (osName=\"" + System.getProperty("os.name") + "\").");
    }
    System.out.println((++lineNr) + ". " + s);
}


public void stop() {
    if (runner != null) {
        runnerx = runner;
        runner = null;
        runnerRunning = false;
        try {
            runnerx.join();
        } catch (Exception e) {
        }
        gbuf.dispose();
        removeMouseListener(this);
        printme("Exiting stop method");    
    }
}


public void destroy() {
    printme("In destroy method");
    stop();
}


public void run() {

    gbuf.setFont(f);
    gbuf.setColor(Color.black);
    gbuf.copyArea(0, tHeight, tWidth, tHeight, 0 ,-tHeight);    // initialize display area
    tHeightX = tHeight;
    printme("Gonna loop in run method");
    while (runnerRunning) {
        try {
            repaint(); 
            Thread.sleep(tRate); 
        }
        catch (InterruptedException e) { 
        }
    }
}


public void update(Graphics g) {
    paint(g);
}

static boolean lc = true;
public void paint(Graphics g) {

    //nowGMT.setTime(new Date());
    // Problem with setting TimeZone "GMT+01" requires that we compute that
    // value ourselves, so thet nowGMT isn't GMT any more, but GMT+01.
    now = new Date();
    now.setTime(now.getTime() + 60*60*1000);
    nowGMT.setTime(now);
    
    int hr24 = nowGMT.get(Calendar.HOUR_OF_DAY);
    int min = nowGMT.get(Calendar.MINUTE);
    int sec = nowGMT.get(Calendar.SECOND);
    int yrInt = nowGMT.get(Calendar.YEAR);
    int moInt = nowGMT.get(Calendar.MONTH) - nowGMT.getMinimum(Calendar.MONTH) + 1;
    int daInt = nowGMT.get(Calendar.DAY_OF_MONTH);
    //String yr = String.valueOf(yrInt);
    //String mo = (moInt < 10 ? "0" : "") + String.valueOf(moInt);
    //String da = (daInt < 10 ? "0" : "") + String.valueOf(daInt);
    String atNow = "@" + String.valueOf(yrInt) + "-" + ((moInt < 10 ? "0" : "") + String.valueOf(moInt)) +
                            "-" + ((daInt < 10 ? "0" : "") + String.valueOf(daInt));

    int secondInDay = ((hr24 * 60)  + min) * 60 + sec;
    int SwatchBeatInt = (int)(((double)100000)*((double)secondInDay/(double)(24*60*60)));
    String SwatchBeat = "000" + String.valueOf(SwatchBeatInt/100);
    //SwatchBeat = SwatchBeat.substring(SwatchBeat.length() - 3);
    String frac = "00" + String.valueOf(SwatchBeatInt % 100);
    //frac = frac.substring(frac.length() - 2);
    atNow += " @" + SwatchBeat.substring(SwatchBeat.length() - 3) + "." +
                            frac.substring(frac.length() - 2); 

    //int vAdj = (int)(tHeight / 2)  + (int)(char_ascent / 3);
    if (lc) {
        printme("vAdj=" + vAdj + ".");
        lc = false;
    } 

    //int fixedPart = 149;
    //gbuf.copyArea(fixedPart,tHeight, tWidth - fixedPart, tHeightX, 0 ,-tHeightX); // Restore image background
    gbuf.copyArea(0, tHeight, tWidth, tHeightX, 0 ,-tHeightX); // Restore image background
                                                               // (different image if mouse over Applet)
 
    //gbuf.drawString("@" + yr + "-" + mo + "-" + da + " @" + SwatchBeat + "." + frac,
    gbuf.setFont(f);
    gbuf.drawString(atNow,
                   150, vAdj);                                 // format: @2000-08-04 @900.00
                 
    g.drawImage(buffered_image, 0, 0, null);
}

//**** Hilite applet when mouse is over it (esp. since I can't figue out how to get a tooltip) ****
//class MyMouseListener extends MouseAdapter {

public void mouseClicked(MouseEvent me) {

    printme("mouseClicked method entered for URL: " + URLString);
    URL theURL;
    if (getDocumentBase().getProtocol().equalsIgnoreCase("http")) {
        try { 
            theURL = new URL(URLString); 
        } catch (Exception e) {
            printme("Could not resolve URL: " + URLString);
            return;
        }
        printme("Linking to: " + URLString);

        getAppletContext().showDocument(theURL);
        return;
    }
    repaint();
}

public void mousePressed(MouseEvent me) {
}
public void mouseReleased(MouseEvent me) {
}

public void mouseExited(MouseEvent me) {
    printme("mouseExited method entered");
    tHeightX = tHeight;
    repaint();
}

public void mouseEntered(MouseEvent me) {
    printme("mouseEntered method entered");
    tHeightX = tHeight * 2;
    repaint();
}

//} // end inner class MyMouseListener

} // end SwatchTime clock



<< SwatchTime.java  L: 10,255. A: 100444. M: 2002-03-27 16:29:25 UTC [=1017246565] -5721.10d <<

[ Please note: ]  Some systems do not provide this script with a return address (the HTTP_REFERER cgi environment variable). In those cases, the "Return" icon at right is disabled, but you can still use your web browser's BACK button to return to the page from which you came to here. I apologize. Thank you for your understanding.

Page generated by:
http://www.users.cloud9.net/~bradmcc/cgi-bin/ascii.pl?f=SwatchTime.java
Copyright © 2001-2005 Brad McCormick, Ed.D.
bradmcc@cloud9.net [ Email me! ]
26 April 2008CE
v10.05
[ ]
[ ]
[ Notice what's hiding in plain sight! ] [ ]
[ ] [ ]
[ Go home! (BMcC website Home page!) ] [ ] [ Use your web browser's BACK button to return to page from which you linked to here! ] [ ]
[ ]
[ Go to Site Map! ] [ ] [ HTML 3.2 Checked! Test me! ] [ ]
[ ]
[ ]
[ Go to website Table of Contents! ] [ ] [ Welcome to my website! Please come in! ]
[ ]
[ ]