简体   繁体   English

如何更新JavaFX canvas?

[英]How to update JavaFX canvas?

I've been working on a GUI for visualizing the layout and working of a basic neural network program that I have been developing and figured the best way would be via JavaFX canvas. 我一直在使用GUI来可视化我一直在开发的基本神经网络程序的布局和工作,并认为最好的方法是通过JavaFX canvas。 Each cycle, the program clears the screen then redraws the status using 在每个循环中,程序都会清除屏幕,然后使用重新绘制状态

GraphicsContext gc = canvas.getGraphicsContext2D();
gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
gc.fillOval(x, y, 30, 30);
gc.strokeLine(x1, y1, x2, y2);

to draw the nodes (ovals) and connections (lines) in the correct places. 在正确的位置绘制节点(椭圆)和连接(线)。 However, instead of updating the display with each iteration as I would expect, the canvas remains blank until all iterations are completed and there is no more drawing being performed on the canvas. 但是,与其像我期望的那样在每次迭代中更新显示,不如在所有迭代都完成并且画布上不再执行绘制之前,画布保持空白。

How do I make the canvas update as it is being drawn onto (ie; changing when the data changes) instead of once all drawing is completed? 如何在绘制画布时(即在数据更改时进行更改)而不是在所有绘制完成后进行画布更新?

Thanks for any help! 谢谢你的帮助!

问题是我的线程没有正确设置,因此正在调用它的线程中暂停进一步的处理,直到完成为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM