Java support

This version of SpecTcl has an experimental java code generator available.

Turning on the Java Support

Java support can be added to SpecTcl by adding the line
		source $Base_dir/java_setup.tk
to the file SpecTclrc in your home directory. Make sure that the java compiler (javac) and interpreter (java) are in your execution path.

Using the Java support

The Java support adds two additional commands to the edit menu:
Java
Causes a java file to be generated, compiled, and tested.
Kill java
Kills any existing java test
In addition, the file java.project in the current directory is sourced when the java support is first loaded, and may be used to add project specific behavior to the generated java code as explained below.

The Java code generator

The Java code generator defines a new class, whose name is the same as the SpecTcl project name. By default, the class extends java.applet.Applet, and is placed in the default package. The class contains the following items:

Interfacing to application code

Application specific code is specified by using the action option for each widget. The actions are java statements to be invoked when the action occurs. Normally the statement is expected to be a Java method call. The local variable event of class Event is available to pass to the method as an argument. The event class contains both a handle to the widget and to the event that is being performed.

The file java.project in the current directory contains TCL code to tailor the code generator for a specific application. The following sample is illustrative: form:

	set P(extends) my_app     ;# extend my_app instead of Applet
	set P(package) my_package ;# place the code in package my_package
	set P(export)  check      ;# add an class instance array with this property
	set P(other_items:entry) check  ;# add option check to all entry widgets
SpecTcl allows application specific options to be added to widgets, which is then passed through to the java code. P(export) contains a list of option names, each of which causes a class instance variable of type String[] to be generated that contains the the value of that option for each widget. Widgets that do not have that property are given a string value of null. P(otheritems:widget_name) contains a list of options that are added to the option sheet for the widget widget_name. generated.

Sample java generated code

This is a sample of the code generated for an interface with a single button, hello, that prints the word "hello" when pressed: