[Date Index] [Thread Index] [Author Index]
Re: Trying to do some stuff with JLINK ???
On 28/05/10 12:23, jalbers wrote: > Get["JLink`"] > InstallJava > k = JavaNew["javax.swing.JOptionPane"] > k@showMessageDialog["Welcome to Java"] Here is some working code: Needs["JLink`"] InstallJava; LoadJavaClass["javax.swing.JOptionPane"]; javax`swing`JOptionPane`showMessageDialog[Null, JavaNew["java.lang.String", "Welcome to Java"]]; Note that the method you are trying to call is a static method, so you load the class as shown, and all the static methods appear as functions in the nested contexts corresponding to the full Java class name. Note also that the method you needed to call was a slightly tricky case because it takes a string in the form of an object. This meant that it was necessary to explicitly create a string object (which then gets automatically cast to object type. Methods that take explicit string arguments don't need this - J/Link does this step automatically. I am not sure why LoadJavaClass["javax.comm.CommPortIdentifier"] fails - I suspect it lies in an extra library that you will need to download and add to your class path. If you are going to make more than trivial use of Java, I would suggest putting your code in a Java file and compiling it - using J/Link to call one or more of the methods you have written. You do need some knowledge of Java to do much with JLink :( David Bailey http://www.dbaileyconsultancy.co.uk