SUN Java SpreadSheet (version 1.17)
This page shows how to compile a more complex java project such as a spreadsheet applet using ORACLE's JDK (Java Development Kit). This example creates several class files that can be placed on a website, or all placed in one jar and then installed on a website, to be used by a java enabled Internet browser such as Internet Explorer, FireFox, Safari, Opera, Konqueror.
SUN Example Spreadsheet With Several Class Files In One Jar
The HTML code shown below was used to display the spreadsheet seen above.
<applet code="spreadsheet.class" archive="spreadsheet.jar" width=318 height=120> <param name=title value="Example 2">
<param name=columns value="3"> <param name=rows value="4">
<param name=c3 value="fC1+C2"> <param name=c2 value="fA2*B2">
<param name=c1 value="fA1*B1"> <param name=b2 value="v1000">
<param name=b1 value="v500"> <param name=a2 value="v30">
<param name=a1 value="v10">
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> |
The syntax for the simple spreadsheet above is either 'f' for a formula (followed by a formula to be computed) or 'v' for a value (followed by a value or pointer to another cell which does not require calculating a result):
- formula -> value
- formula -> value op value
- value -> '(' formula ')'
- value -> cell (example: a pointer to cell A2 is entered as vA2)
- value -> <number> (example: a value of 5 is entered as v5)
- op -> '+' | '*' | '/' | '-' (Spreadsheet understands these operators)
- cell -> <letter><number> (example: cell=A1 or cell=B2)
SPREADSHEET SOURCE FILES
spreadsheet.java SUN source code needed to build compressed binary jar file (21.3KB).
spreadsheet.jar compressed java binary archive used by this web page (11.3KB).
spreadsheet.sh script used here for automatic compiling (464 bytes).
COMPILE JAVA MANUALLY
To compile "spreadsheet.java" source code manually into a compressed "spreadsheet.jar", follow these steps on the command line:
1.
2.
3.
4.
5.
6.
7. | |
[you@genesis ~]$ cd ~/temp
[you@genesis temp]$ javac -deprecation spreadsheet.java
2 warnings
[you@genesis temp]$ ls -l
-rw-r--r-- 1 you you 4991 2008-08-08 12:08 celldata.class
-rw-r--r-- 1 you you 1552 2008-08-08 12:08 cellupdater.class
-rw-r--r-- 1 you you 2086 2008-08-08 12:08 inputfield.class
-rw-r--r-- 1 you you 1679 2008-08-08 12:08 nodedata.class
-rw-r--r-- 1 you you 7530 2008-08-08 12:08 spreadsheet.class
-rw-r--r-- 1 you you 1554 2008-08-08 12:08 spreadsheetinput.class
-rw-r--r-- 1 you you 21795 2008-08-08 12:07 spreadsheet.java
[you@genesis temp]$ jar cvf spreadsheet.jar spreadsheet.class spreadshee
tinput.class celldata.class cellupdater.class inputfield.class nodedata.
class
added manifest
adding: spreadsheet.class(in = 7530) (out= 3951)(deflated 47%)
adding: spreadsheetinput.class(in = 1554) (out= 889)(deflated 42%)
adding: celldata.class(in = 4991) (out= 2804)(deflated 43%)
adding: cellupdater.class(in = 1552) (out= 948)(deflated 38%)
adding: inputfield.class(in = 2086) (out= 1204)(deflated 42%)
adding: nodedata.class(in = 1679) (out= 1002)(deflated 40%)
[you@genesis temp]$ rm -f *.class
[you@genesis temp]$ ls -l
-rw-r--r-- 1 you you 11895 2008-08-08 12:09 spreadsheet.jar
-rw-r--r-- 1 you you 21795 2008-08-08 12:07 spreadsheet.java
[you@genesis temp]$ exit |
|
- cd ~/temp - Change to the directory holding your "spreadsheet.java" source code. This example assumes you placed your project in directory "~/temp".
- javac -deprecation spreadsheet.java - Compile the 21.3KB java text file into several java class binary files (spreadsheet.class, spreadsheetinput.class, celldata.class, cellupdater.class, inputfield.class, nodedata.class).
The "-deprecation" option is used in this example since "spreadsheet.java" came from the 1.4.2 JDK toolkit, plus you may want to be as backward compatible as you can for the widest audience possible.
- ls -l - This step is optional. List the class files created.
- jar cvf spreadsheet.jar spreadsheet.class spreadsheetinput.class celldata.class cellupdater.class inputfield.class nodedata.class - Create a compressed jar file (11.3KB) from the class binary files (total=18.9KB). The jar file is smaller and quicker to send than several class files.
- rm -f *.class - This cleanup step is optional. If you are creating a compressed jar file, then you do not need to keep the class files.
- ls -l - This step is optional. List the resulting files.
- exit - You are done.
COMPILE JAVA BY SCRIPT
This "spreadsheet.sh" script below is a more complex script compared to "clock.sh" but it allows you to automatically compile the "spreadsheet.java" code all in one step. Use it as an example script which you can use as a template for more complex projects where you may have several class files. This script assumes your spreadsheet java project is in directory "~/temp"
#!/bin/sh cd ~/temp
# Create compiled code from java file. javac -deprecation spreadsheet.java
# Create compressed jar from compiled files. jar cvf spreadsheet.jar spreadsheet.class spreadsheetinput.class celldata.class cellupdater.class inputfield.class nodedata.class
# Cleanup results. class files not needed. rm -f spreadsheet.class spreadsheetinput.class celldata.class cellupdater.class inputfield.class nodedata.class
# Show results ls -l spreadsheet.*
|
Follow the steps below to compile this project.
1.
2. | |
[you@genesis ~]$ sh ~/temp/spreadsheet.sh
2 warnings
added manifest
adding: spreadsheet.class(in = 7530) (out= 3951)(deflated 47%)
adding: spreadsheetinput.class(in = 1554) (out= 889)(deflated 42%)
adding: celldata.class(in = 4991) (out= 2804)(deflated 43%)
adding: cellupdater.class(in = 1552) (out= 948)(deflated 38%)
adding: inputfield.class(in = 2086) (out= 1204)(deflated 42%)
adding: nodedata.class(in = 1679) (out= 1002)(deflated 40%)
-rw-r--r-- 1 you you 11895 2008-08-08 12:10 spreadsheet.jar
-rw-r--r-- 1 you you 21795 2008-08-08 12:07 spreadsheet.java
-rwxr-xr-- 1 you you 464 2008-08-08 12:09 spreadsheet.sh*
[you@genesis ~]$ exit |
|
- sh ~/temp/spreadsheet.sh - Run the script to do all the steps needed to build this jar file. This project is assumed to be located in directory "~/temp".
- exit - You are done.