2

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?

Say.My.Name.
  • 511
  • 5
  • 19
  • 1
    What is the exception? – Kninnug Apr 17 '13 at 21:54
  • 1
    It might be easier to run the GUI in a subprocess (see `java.lang.ProcessBuilder`); Java's subprocess handling is not really all that great, but it beats working with a large chunk of unported code! – Donal Fellows Apr 18 '13 at 05:13
  • @DonalFellows Thank you for the help. I simply started the tcl wish shell in a subprocess and executed my tcl script. – Say.My.Name. May 08 '13 at 18:49

2 Answers2

0

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).

Johannes Kuhn
  • 14,778
  • 4
  • 49
  • 73
0

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
Zak
  • 11
  • 1
  • Could you please explain your answer in a few sentences instead of simply dumping the code inhere? – Daniel Dec 10 '14 at 00:05