I am trying to create a Java frontend for Mathematica. Following examples from J/Link guide and looking around the API manual I came up with this code:
public class Mathematica extends MathJFrame {
public Mathematica(String[] args) {
initComponents();
try {
ml = MathLinkFactory.createKernelLink(args);
} catch (MathLinkException e) {
System.out.println("Fatal error opening link: " + e.getMessage());
}
try {
ml.discardAnswer();
ml.evaluate("2+2");
ml.waitForAnswer();
int result = ml.getInteger();
System.out.println("2 + 2 = " + result);
graphic1.setLink(ml);
graphic1.setMathCommand("Plot[x,{x,0,1}]");
graphic1.repaintNow();
System.out.println(graphic1.getMathCommand());
} catch (MathLinkException e) {
System.out.println("Fatal error opening link: " + e.getMessage());
} finally {
ml.close();
}
private KernelLink ml = null;
}
Graphics.java:
public class Graphic extends MathGraphicsJPanel {
public Graphic() {
}
}
I know the link is working because I get 2 + 2 = 4 displayed in console but the panel where the graph output is expected is empty. Also, does J/Link not ship with sample programs anymore?
Thanks for any suggestions.