Needs["JLink`"];
InstallJava[];
PlotAppletwithAdjustment[] := 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];

domainLabel = JavaNew["javax.swing.JLabel", "x goes from 0 to"];
domainLabel@setBounds[110, 60, 120, 20];
panel@add[domainLabel];

plotDomainText = JavaNew["javax.swing.JLabel", "10"];
plotDomainText@setBounds[220, 60, 20, 20];
panel@add[plotDomainText];

scrollbar = JavaNew["javax.swing.JScrollBar", 0, 10, 1, 10, 50];
scrollbar@setBounds[100, 80, 150, 20];
panel@add[scrollbar];

scrolllistener = JavaNew["com.wolfram.jlink.MathAdjustmentListener"];
scrolllistener@setHandler["adjustmentValueChanged", "scrollbarFunc"];
scrollbar@addAdjustmentListener[scrolllistener];

scrollbarFunc[_, _, scrollPos_] :=
JavaBlock[Module[{}, plotDomainText@setText[ToString[scrollPos]]]];

mathCanvas = JavaNew["com.wolfram.jlink.MathCanvas"];
mathCanvas@setBounds[50, 100, 250, 220];
panel@add[mathCanvas];

plotButton = JavaNew["javax.swing.JButton", "Plot"];
plotButton@setBounds[150, 320, 60, 20];
panel@add[plotButton];
buttonListener = JavaNew["com.wolfram.jlink.MathActionListener"];
buttonListener@setHandler["actionPerformed", "buttonFunc"];
plotButton@addActionListener[buttonListener];

buttonFunc[_, _] :=
JavaBlock[
Module[{plotFunction, plotDomain},
plotFunction = functionField@getText[];
plotDomain = plotDomainText@getText[];
mathCanvas@
setMathCommand[
"Plot[" <> plotFunction <> ", {x, 0, " <> plotDomain <> "},
Background -> GrayLevel[.8], PlotStyle -> RGBColor[0, 0, 1]]"]]];


frame@getContentPane[]@add[panel];
frame@setSize[360, 380];
frame@layout[];
JavaShow[frame];
frame@setModal[];
DoModal[];]

PlotAppletwithAdjustment[]


Back to main page