Tag: 时间轴

JavaFX无限时间轴中的内存泄漏

我正在使用JavaFX设计秒表。 代码运行良好。 除了巨大的累积内存泄漏随着时间的推移。 每当我增加Timeline的framerate时,泄漏就会增加。 我目前使用的是4GB内存的Ubuntu 16.04,泄漏速度为300MB / min,速度为30fps。 那是5MBps。 我可以理解,这可能是由于重复绘制Scene而发生的,但为什么会累积? JVM不应该照顾这个吗? Main.java: package UI; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ButtonBar; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ primaryStage.setTitle(“StopWatch”); primaryStage.setScene(new Scene(getPane(), 400, 400)); primaryStage.show(); } private BorderPane getPane(){ BorderPane pane = new BorderPane(); ClockUI […]

如何让球在JavaFX中从墙上弹开?

我是Javafx的新手,我正在创建一个简单的程序。 我想要实现的是让球从墙上反弹,但我还没弄明白该怎么做。 另外,请随意留下有关我的代码的其他建议。 这是源代码: public class GamePractice extends Application { public static Circle circle; public static Pane canvas; private long counter = 0; @Override public void start(Stage primaryStage) { canvas = new Pane(); Scene scene = new Scene(canvas, 800, 600); primaryStage.setTitle(“Game”); primaryStage.setScene(scene); primaryStage.show(); circle = new Circle(15,Color.BLUE); circle.relocate(100, 100); canvas.getChildren().addAll(circle); Timeline loop = new Timeline(new […]