Java and Mathematica
Java and Mathematica
Java and Mathematica
myWindow = JavaNew["com.wolfram.jlink.MathJFrame"];
myWindow@setSize[200, 200];
myWindow@setLocation[300, 300];
JavaShow[myWindow];
Constructors["java.awt.Button"]
Fields["java.awt.Button"]
Methods["java.awt.Button", "set*"]
Java Mathematica
Constructors MyClass obj obj =
= new MyClass( args ); JavaNew["MyClass", args]
Fields["java.awt.Button"]
Lists all fields of the Button class.
Methods["java.awt.Button", "set*"]
Lists all methods of the Button class that begin with set.
KernelLink ml = MathLinkFactory.createKernelLink(argv1);
Evaluate Expression
ml.evaluate("2+2");
ml.waitForAnswer();
ml.discardAnswer();
Image img = ml.evaluateToImage(
"Plot[Sin[x], {x, 0, 2Pi}]",
450, 450);
Sample Code
KernelLink ml = null;
// Create a KernelLink
try {
ml = MathLinkFactory.createKernelLink(argv1);
}
catch (MathLinkException e) {
System.out.println("Fatal error opening link: " + e.getMessage());
return;
}
try {
// Get rid of the initial InputNamePacket the kernel
// will send when it is launched.
ml.discardAnswer();
ml.evaluate("<<MyPackage.m");
ml.discardAnswer();
ml.evaluate("2+2");
ml.waitForAnswer();
}
catch (MathLinkException e)
{
System.out.println("MathLinkException occurred: " + e.getMessage());
}
finally
{
// Close the KernelLink
ml.close();
}
Output from Sample Code
2 + 2 = 4
3 + 3 = 6
4 + 4 = 8
4 + 4 = Sin[x]
Further Reading
Web:
http://www.wolfram.com/solutions/mathlink/jlink/documentation/api/
Local Drive:
C:\Program Files\Wolfram
Research\Mathematica\5.2\AddOns\JLink\Documentation\JavaDoc\index.html