Needs["JLink`"];
InstallJava[];
PlotApplet[] := Module[{},
frame = JavaNew["com.wolfram.jlink.MathJFrame"];
panel = JavaNew["javax.swing.JPanel"];
panel@setLayout[Null];
titleLabel = JavaNew["javax.swing.JLabel", "Generate a
plot of your function, with respect to x."];
titleLabel@setBounds[10, 0, 350, 20];
panel@add[titleLabel];
functionField = JavaNew["javax.swing.JTextField", "Sin[x]^2/Sqrt[x]"];
functionField@setBounds[100, 30, 150, 20];
panel@add[functionField];
mathCanvas = JavaNew["com.wolfram.jlink.MathCanvas"];
mathCanvas@setBounds[50, 50, 250, 220];
panel@add[mathCanvas];
plotButton = JavaNew["javax.swing.JButton", "Plot"];
plotButton@setBounds[150, 270, 60, 20];
panel@add[plotButton];
buttonListener = JavaNew["com.wolfram.jlink.MathActionListener"];
buttonListener@setHandler["actionPerformed", "buttonFunc"];
plotButton@addActionListener[buttonListener];
buttonFunc[_, _] :=
JavaBlock[
Module[{plotFunction}, plotFunction = functionField@getText[];
mathCanvas@setMathCommand["Plot[" <> plotFunction <> ", {x, 0, 10},
Background -> GrayLevel[.80]]"]]];
frame@getContentPane[]@add[panel];
frame@setSize[360, 320];
frame@layout[];
JavaShow[frame];
frame@setModal[];
DoModal[];]

PlotApplet[]


Back to main page