【发布时间】:2021-12-17 05:24:54
【问题描述】:
我目前的情况是,我在屏幕上有一个圆圈,如果我先按住 LMB 然后将光标拖过它,什么也不会发生。我已经尝试过查看我可以使用的不同 EventHandler,但我无法让它们工作。这是我的代码。
public class DragTester extends Application
{
public static Group group = new Group();
public static Scene scene = new Scene(group, 500, 500);
@Override
public void start(Stage stage)
{
for(int i = 0; i < 3; i++){
DragBox DB = new DragBox(i * 150 + 100);
}
stage.setScene(scene);
stage.show();
}
}
public class DragBox
{
private Circle c = new Circle(0, 0, 25);
public DragBox(double x){
DragTester.group.getChildren().add(c);
c.setLayoutX(x);
c.setLayoutY(250);
c.setOnDragDetected(new EventHandler<MouseEvent>(){
@Override public void handle(MouseEvent e){
c.setFill(Color.rgb((int)(Math.random() * 255), (int)(Math.random() * 255), (int)(Math.random())));
}
});
}
}
【问题讨论】: