我遇到了一个问题,过去两天我一直在苦苦挣扎。我有一个编译的程序,可以运行一些模拟并在 SVG 文件中可视化结果。该文件每 2 秒更换一次新文件,直到模拟完成。
为了可视化结果,我制作了一个 java swing 程序,它使用 batik 和 JSVGCanvas 来显示 svg 文件并每 2 秒更新一次。
我使用的代码是:
// In the main part of my code
svgCanvas = new JSVGCanvas();
oneLineInnerPanel.add("Center", svgCanvas);
(new Thread() {
@Override
public void run() {
try {
Thread.sleep(2000);
File f = new File("file_that_shows_simulation_still_running");
while (f.exists()) {
svgReloadButtonActionPerformed(null);
Thread.sleep(2000);
}
} catch (InterruptedException ex) {
Logger.getLogger(testUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}).start();
// -----------------------------------------------
private void svgReloadButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
svgCanvas.loadSVGDocument(SVGFile.toURL().toString());
} catch (MalformedURLException ex) { …Run Code Online (Sandbox Code Playgroud)