-1
我想知道如何绘制和连接JavaFX中的线条或多段线。 我的代码指出错误,在事件中我不能使用场景,也不会使用root或任何这些变量来输出折线。任何人都可以使用我使用的这些数据结构来帮助我或发布代码(所以它不会那么混乱)?如何在JavaFX中绘制多段线?
这里是我的代码:
public void start(Stage stage) {
VBox box = new VBox();
final Scene scene = new Scene(box, 300, 250);
scene.setFill(null);
double x=0.0,y=0.0;
EventHandler filter = new EventHandler<InputEvent>() {
@Override
public void handle(InputEvent event) {
Line line = new Line();
line.setStartX(0.0f);
line.setStartY(0.0f);
line.setEndX(100.0f);
line.setEndY(100.0f);
box.getChildren().add(line);
}
};
// Register the same filter for two different nodes
scene.addEventFilter(MouseEvent.MOUSE_PRESSED, filter);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
我想什么是真正的事件中,能够显示每个Poliline状态。
你得到什么错误? –
我在建模时遇到了问题,我想通过连接它们的线路来解决问题。在这一行中: Box.getChildren()。添加(line); 每次事件运行时我都无法添加到框中?我不理解如何与鼠标事件沟通我的盒子 –
在问题中,你说它给出了一个错误。什么是实际的错误?当我运行你发布的代码时,我没有看到任何错误(我看到了行,但可能没有做你想做的事)。 –