package com.mindprod.inauguration;
import com.mindprod.common11.BigDate;
import com.mindprod.common11.Hybrid;
import com.mindprod.common11.VersionCheck;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Label;
/**
* calculate time to next inauguration. Use BigDate.age in a GUI. Demonstrates use of BigDate.age
*
*
* @author Roedy Green, Canadian Mind Products.
* @version 1.2, 2006-03-05
*/
public final class Inauguration extends Applet
{
/**
* undisplayed copyright notice
*/
public static final String EMBEDDED_COPYRIGHT =
"copyright (c) 2000-2008 Roedy Green, Canadian Mind Products, http://mindprod.com";
private static final String RELEASE_DATE = "2006-03-06";
/**
* embedded version string
*/
private static final String TITLE_STRING = "Inauguration";
/**
* embedded version string
*/
private static final String VERSION_STRING = "1.2";
/**
* height of applet box in pixels. Does not include surrounding frame.
*/
private static final int APPLET_HEIGHT = 30;
/**
* Width of applet box in pixels.
*/
private static final int APPLET_WIDTH = 600;
/**
* year of the next inauguration
*/
private static final int inaugYear = 2009;
/**
* where we display time to next inauguration
*/
private Label time;
/**
* Standard method to initialise the applet
*/
public void init()
{
if ( !VersionCheck.isJavaVersionOK( 1, 1, 0, this ) )
{
return;
}
setVisible( false );
setBackground( Color.green );// none should show if all is well.
setLayout( null );
BigDate inauguration = new BigDate( inaugYear, 1, 20 );
BigDate today = BigDate.localToday();
int[] age = BigDate.age( today, inauguration );
StringBuffer sb = new StringBuffer( 100 );
if ( age[ 0 ] > 0 )
{
sb.append( age[ 0 ] );
sb.append( ( age[ 0 ] == 1 ) ? " year, " : " years, " );
}
if ( age[ 1 ] > 0 )
{
sb.append( age[ 1 ] );
sb.append( ( age[ 1 ] == 1 ) ? " month, " : " months, " );
}
if ( age[ 2 ] > 0 )
{
sb.append( age[ 2 ] );
sb.append( ( age[ 2 ] == 1 ) ? " day, " : " days, " );
}
sb.append( "left to the end of the current Bush administration." );
time = new Label( sb.toString(), Label.CENTER );
time.setBackground( Color.black );
time.setForeground( Color.yellow );
time.setFont( new Font( "Dialog", Font.BOLD, 14 ) );
time.setSize( this.getSize() );
add( time );
setVisible( true );
}
/**
* Allow this applet to run as as application as well.
*
* @param args command line arguments are ignored.
*/
public static void main( String args[] )
{
Hybrid.fireup( new Inauguration(),
TITLE_STRING + " " + VERSION_STRING,
APPLET_WIDTH,
APPLET_HEIGHT );
}
}