On Tue, 07 Mar 2006 00:00:08 +0000
"Mike Price" <mik...@ho...> wrote:
> I am currently working on a final year project where I am using tcl to
> interact with my JAVA program. I have used msys to build the following
> programs (for Windows)
>
> >tcl8.4.12
> >thread2.6.2
> >tclBlend1.3.2
> >Installed j2sdk1.4.2_11
>
> I have enabled threads for all of them and built them all without any
> errors. I am then running jtclsh.bat in the command window and using the
> '%package require java' were it is returning 1.3.2 which is assume is
> correct.
>
> I have also developed a basic JAVA program with a simple class called
> 'Hello' that I want to use to simply store the string sent from the tcl
> interpreter in a variable and then display the variable while running the
> java program. Then I have run the following to try and send a variable to
> JAVA:
>
> % set jstr [java::new String "A Java String"]
> java0x1
>
> Im guessing that java0x1 is the variable name that I need to reference but
> how do I use this variable in my JAVA program?
Well, java0x1 is a Java ref to an object. You need to pass it to a Java method
like so:
public class Test {
static String str;
public static void mymethod(String in_str) {
str = in_str;
}
}
Then you would invoke this Java method from Tcl like so:
set jstr [java::new String "A Java String"]
java::call Test mymethod $jstr
cheers
Mo DeJong
P.S.
You could also look into setting a field of a Java object using java::field.
|