如何在继续按下块之前强制GraphicsContext或Canvas等待绘图任务完成?
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.clearRect(0, 0, width, height);
gc.drawImage(pause, firstImageX, y);
gc.drawImage(cancel, leftImageX, y);
gc.drawImage(complete, rightImageX, y);
Platform.runLater(() -> {
try {
gc.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
});
//other stuff
我试过了
try {
gc.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
它会更新画布,但是我收到错误
Exception in thread "JavaFX Application Thread" java.lang.IllegalMonitorStateException
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:502)
at captureGIF.CaptureGIF.lambda$null$6(CaptureGIF.java:176)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
谢谢!