我有一个应用程序的示例,用于绘制图片GraphicsContext
并如下图所示工作。
问题是select and move只有blue circle
水平地与Canvas
MouseEvent
and MouseClicked
public class JavaFXTest extends Application {
@Override
public void start(Stage primaryStage) {
Group root = new Group();
Canvas canvas = new Canvas(300,100);
GraphicsContext gc = canvas.getGraphicsContext2D();
Stop[] stops;
LinearGradient gradient;
// outer circle
stops = new Stop[]{new Stop(0, Color.LIGHTSKYBLUE), new Stop(1, Color.BLUE)};
gradient = new LinearGradient(0.5, 0, 0.5, 1, true, CycleMethod.NO_CYCLE, stops);
gc.setFill(gradient);
gc.fillOval(10, 14, 40, 40);
gc.fill();
gc.stroke();
// Inner circle
stops = new Stop[]{new Stop(0, Color.BLUE), new Stop(1, Color.LIGHTSKYBLUE)};
gradient = new LinearGradient(0, 0, 1, 1, true, CycleMethod.NO_CYCLE, stops);
gc.setFill(gradient);
gc.fillOval(13, 17, 34, 34);
gc.fill();
gc.stroke();
root.getChildren().add(canvas);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
这就是结果:
可以选择blue circle
in canvas
with canvas.setOnMouseClicked
并搬入水平的 with canvas.setOnMouseMoved
,在不知道的情况下position of blue circle
? –
canvas.setOnMouseMoved((MouseEvent e) -> {
});
canvas.setOnMouseClicked((MouseEvent e) -> {
});