Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You might be able to adapt this Swing based <a href="http://groups.google.com/group/comp.lang.java.programmer/msg/c81f8c5f269e22e5" rel="nofollow noreferrer">Launcher</a> that uses <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/ProcessBuilder.html" rel="nofollow noreferrer"><code>ProcessBuilder</code></a> to run programs in a separate JVM.</p> <p><a href="https://i.stack.imgur.com/iufvi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iufvi.png" alt="image"></a></p> <pre><code>package gui; import java.awt.EventQueue; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; /** * @see http://stackoverflow.com/a/5696404/230513 */ public class Launcher extends JPanel implements Runnable { private final JLabel label = new JLabel(); private final JButton launch = new JButton(); ProcessBuilder pb = new ProcessBuilder( "java", "-cp", "build/classes", "gui.Launcher$DialogTest"); private volatile Process proc; public static void main(String[] args) { EventQueue.invokeLater(new Launcher()::createGUI); } private void createGUI() { final JFrame frame = new JFrame(); frame.setLayout(new GridLayout(0, 1)); frame.add(new Launcher()); frame.add(new Launcher()); frame.add(new Launcher()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } public Launcher() { this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); launch.setAlignmentX(0.5f); label.setAlignmentX(0.5f); launch.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (proc == null) { launch.setText("Terminate"); label.setText("Status: run"); new Thread(Launcher.this).start(); } else { proc.destroy(); reset(); } } }); this.add(launch); this.add(label); reset(); } @Override public void run() { try { proc = pb.start(); proc.waitFor(); } catch (IOException | InterruptedException ex) { ex.printStackTrace(System.err); } EventQueue.invokeLater(this::reset); } private void reset() { proc = null; launch.setText("Launch"); label.setText("Status: idle"); } private static class DialogTest { public static void main(String[] args) { EventQueue.invokeLater(() -&gt; { JOptionPane.showMessageDialog(null, "Running", "Test", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }); } } } </code></pre> <p><sup><em>Updated to Java 8 at the author's request.</em></sup></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload