我一直在用Java編寫一個模擬程序,現在用JavaFX生成結果圖。然而,我很難理解如何調用圖表,以便當我嘗試第二次運行模擬(並生成圖表)時,我不會看到「不能調用launch()多於一次「錯誤。我讀過launch()只能調用一次,那麼在模擬的第二次運行中,我需要更改以成功調用圖形?如何「重新啓動」JavaFX應用程序?
public class AnswerWorker extends SwingWorker<Void, Integer> {
protected Void doInBackground() throws Exception
{
AMEC.runsimulation();
return null;
}
protected void done()
{
try {
Graphs.launch(Graphs.class, "");
JOptionPane.showMessageDialog(InputGUI.this, AMEC.unsuccesfulpercentage + "% of iterations had trucks that had to sleep over");
AMEC.unsuccesfulpercentage = 0;
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
用非常標準的圖形類:
public class Graphs extends Application {
@Override public void start(Stage stage) {
....
stage.show();
}
}
在你的[上一個問題]中,Sebastian(http://stackoverflow.com/questions/21132278/is-it-possible-to-draw-graphs-using-javafx-in-a-normal-java-application),Sebastian給出了這個答案:使用'JFXPanel'。 –