Opening a TCL gui within Java code

820 views Asked by At

I have a TCL file which uses Tcl's BWidget package that I've been using as a GUI for my program. I now want to be able to load up this GUI from a separate Java program. I've looked into Jacl and Swank, but they don't seem to do exactly what I want.

I've tried the following with Jacl but it's unable to evaluate the file. While debugging, I can see that it completes parsing my tcl file, but it throws an exception while parsing through the BWidget package tcl files. Here's my Java code:

Interp interp = new Interp();
try {
    interp.evalFile("C:\\CTP\\Tcl\\LuxonCtp32.tcl");
} catch (TclException ex) {
    int code = ex.getCompletionCode();
    System.err.println("command returned bad error code: " + code);
} finally {
    interp.dispose();
}

Any ideas on how I can accomplish what I want to do? Is it even possible?

2

There are 2 answers

1
Zak On

Go to this site http://jtcl-project.github.io/jtcl/ and download now for the binary zip. Its a recent java tcl on github called Jtcl. Unzip it and you will find a jar called jtcl-2.7.0.jar. I am using Netbeans 8 my preference. I add the jar into Project Library. I create a java file called JTclHallo.java and this is the code.

package jtclhallo;
// import tcl.lang it belongs to jtcl-2.7.0 jar a must

import tcl.lang.*;

 // Java wrapper to test JACL or JTCL.

public class JTclHallo {
    public static void main(String []args) {

        //Interp is a java class belonging to tcl.lang. Unrar the jtcl-2.7.0

        Interp i = new Interp();


        try {

            //call your tcl file mine was swing.tcl from the E drive
            i.eval("source E:/private/swing.tcl");
            } catch (TclException e) {
            System.out.println("Exception: " + e.getMessage());
            }

    }
 }

For swing.tcl

package require java

set window [java::new javax.swing.JFrame]
$window setSize 600 400
$window setVisible true
0
Johannes Kuhn On

Tcl itself can not display a GUI. It uses a plugin called Tk for that.
In the C reference implementation of Tcl you get Tk as well.
Tk has not been ported to Java, Tcl has.

You can not use Jacl to display Tk widgets, but TclBlend could do that, because TclBlend uses the C reference implementation of Tcl. That means that the user needs a working Tcl/Tk installation.

There are some problems with TclBlend and Tcl > 8.5 through, which result in a segfault.
IIRC you have to remove the conditional if around Tcl_FindNameOfExecutable in TclBlends C code (and compile it yourself).