Skip to content

Instantly share code, notes, and snippets.

@aomnes
Created June 11, 2017 13:39
Show Gist options
  • Save aomnes/141a1942069d2b9134bc453e297318b7 to your computer and use it in GitHub Desktop.
Save aomnes/141a1942069d2b9134bc453e297318b7 to your computer and use it in GitHub Desktop.
Exemple processus java
public void actionPerformed(ActionEvent arg0) {
ZDialog zd = new ZDialog(null, "General.io", true);
System.out.print(ZDialog.nb_ouverture);
nb_partie = ZDialog.nb_ouverture;
nom_a = zd.get_nom_r();
nom_b = zd.get_nom_b();
actualiser_param();
ZDialogInfo zInfo = zd.showZDialog();
JOptionPane jop = new JOptionPane();
jop.showMessageDialog(null, zInfo.toString(), "Data Game", JOptionPane.INFORMATION_MESSAGE);
Runtime runtime = Runtime.getRuntime();
try {
Process p = runtime.exec("java -jar exec.jar");
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));//ouput processus
out.write(zd.getIncre_t() + "\n");
out.write(zd.getIncre_plaine() + "\n");
out.write("fin" + "\n");
out.flush();
System.out.println("=====> lancement");
setVisible(false);
p.waitFor();
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
System.out.println("ok!");
in.close();
if (p.exitValue() == 1) {
score[0]++;
} else if (p.exitValue() == 2) {
score[1]++;
}
actualiser_param();
setVisible(true);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment