Needs["JLink`"];
InstallJava[];

SimpleModal[] :=
   JavaBlock[
     Module[{frame, button, textField, windowListener, buttonListener,
         buttonFunc}, frame = JavaNew["com.wolfram.jlink.MathJFrame"];
       panel = JavaNew["javax.swing.JPanel"];
       button = JavaNew["javax.swing.JButton", "Increment by one"];
       textField = JavaNew["javax.swing.JTextField", "1", 10];
       panel@add[button];
       panel@add[textField];
       buttonListener = JavaNew["com.wolfram.jlink.MathActionListener"];
       buttonListener@setHandler["actionPerformed", ToString[buttonFunc]];
       button@addActionListener[buttonListener];
       buttonFunc[_, _] :=
         JavaBlock[Module[{curText, newVal}, curText =
textField@getText[];
             newVal = ToExpression[curText] + 1;
             textField@setText[ToString[newVal]]]];
       frame@getContentPane[]@add[panel];
       frame@setSize[200, 100];
       JavaShow[frame];
       frame@setModal[];
       DoModal[];]]

SimpleModal[]


Back to main page