SUN Java Clock (version 1.16)


This page shows how to compile a simple java clock applet using ORACLE's JDK (Java Development Kit) which can run on a java enabled Internet browser such as Internet Explorer, FireFox, Safari, Opera, Konqueror.

This compiled/compressed java binary program has three input parameters which can be set in the HTML code used to call this clock. The parameter values are:

These three parameters above are hexadecimal RGB numbers (like the ones used for the body bgcolor tag in HTML). Here are some sample colors:

Below are 2 clock examples running from the same jar but with different param values passed to the jar within the HTML page:

Default Clock With No Color Parameters Given
alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." Your browser is completely ignoring the <APPLET> tag!

Parameters used to display the code shown above:

<applet code="clock.class" archive="clock.jar" width=170 height=150>
alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason."
Your browser is completely ignoring the <APPLET> tag!
</applet>

Red Clock With A Black Background.
alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." Your browser is completely ignoring the <APPLET> tag!

Clock colors are decided by added HTML param values.

<applet code="clock.class" archive="clock.jar" width=170 height=150>
<param name=bgcolor value="000000">
<param name=fgcolor1 value="ff0000">
<param name=fgcolor2 value="ff00ff">
alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason."
Your browser is completely ignoring the <APPLET> tag!
</applet>


CLOCK SOURCE FILES

clock.java SUN source code needed to build compressed binary jar file (7.6KB).
clock.jar compressed java binary archive used by this web page (2.6KB).
clock.sh script used here for automatic compiling (266 bytes).


COMPILE JAVA MANUALLY

To compile "clock.java" source code manually into a compressed "clock.jar", follow these steps on the command line:
1.
2.
3.

4.



5.
6.
 
[you@genesis ~]$ cd ~/temp
[you@genesis temp]$ javac -deprecation clock.java
[you@genesis temp]$ jar cvf clock.jar clock.class
adding: clock.class(in = 4908) (out= 2637)(deflated 46%)             
[you@genesis temp]$ ls -l
-rw-r--r-- 1 you you 4908 2008-08-08 12:01 clock.class
-rw-r--r-- 1 you you 2781 2008-08-08 12:02 clock.jar
-rw-r--r-- 1 you you 7768 2008-08-08 12:00 clock.java
[you@genesis temp]$ rm clock.class
[you@genesis temp]$ exit

  1. cd ~/temp - Change to the directory holding your "clock.java" source code. This example assumes you placed your project in directory "~/temp".

  2. javac -deprecation clock.java - Compile the 7.6KB java text file into a java binary file. The "-deprecation" option is used in this example since it came from the 1.4.2 JDK toolkit with some modifications, plus you may want to be as backward compatible as you can for the widest audience possible.

  3. jar cvf clock.jar clock.class - Create a compressed jar file (2.6KB) from the class binary file (4.6KB). The jar file is ideal for a web page since it is smaller and quicker to send than a class file.

  4. ls -l - This step is optional. List the clock files.

  5. rm clock.class - This cleanup step is optional. If you are creating a compressed jar file, then you do not need to keep the class file.

  6. exit - You are done.


COMPILE JAVA BY SCRIPT

This "clock.sh" script below is very simple but it allows you to automatically compile the "clock.java" code all in one step. Use it as an example script which you can use as a template for more complex projects. This script assumes your clock java project is in directory "~/temp"

#!/bin/sh
cd ~/temp

# Create compiled code from java file.
javac -deprecation clock.java

# Create compressed jar archive from compiled file.
jar cvf clock.jar clock.class

# Cleanup results; clock.class not needed.
rm -f clock.class

# Show results
ls -l clock.*

Follow the steps below to compile the project.

1.




2.
 
[you@genesis ~]$ sh ~/temp/clock.sh
adding: clock.class(in = 4908) (out= 2637)(deflated 46%)             
-rw-r--r-- 1 you you 2781 2008-08-08 12:02 clock.jar
-rw-r--r-- 1 you you 7768 2008-08-08 12:00 clock.java
-rwxr-xr-- 1 you you  265 2008-08-08 12:00 clock.sh*
[you@genesis ~]$ exit

  1. sh ~/temp/clock.sh - Run the script to do all the steps needed to build a jar file. This project is assumed to be located in directory "~/temp".

  2. exit - You are done.


Other Java Pages On This Web Site
Java Install Example Spreadsheet Example Rubik's Cube A Few Games

Other Pages On This Web Site
Home Page Backup With Tar Disk Image Backup BOINC On Linux android.rules For adb Server
Remove Duplicate Files Remove Spaces In File Names Change MAC Address Ship Arcade PicDis Disassembler



Copyright© 2000..2017 Joe's Cat

counter