当前位置: 首页>>代码示例>>Java>>正文


Java Canvas.setOnMouseClicked方法代码示例

本文整理汇总了Java中javafx.scene.canvas.Canvas.setOnMouseClicked方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.setOnMouseClicked方法的具体用法?Java Canvas.setOnMouseClicked怎么用?Java Canvas.setOnMouseClicked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javafx.scene.canvas.Canvas的用法示例。


在下文中一共展示了Canvas.setOnMouseClicked方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: constructCanvas

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
private void constructCanvas() {
	boardCanvas = new Canvas();

	if ( interactive ) {
		boardCanvas.setOnMouseMoved(this::canvasHover);
		boardCanvas.setOnMouseClicked(this::canvasClicked);
		boardCanvas.setOnMouseExited(this::canvasExit);
	}

	boardPane.getChildren().add(boardCanvas);

	gameDrawer = buildGameDrawer();
	gameDrawer.draw(getGameHandler().getBoard());
}
 
开发者ID:GoSuji,项目名称:Suji,代码行数:15,代码来源:BoardController.java

示例2: setCanvas

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
/**
 * Sets the {@link Canvas} for use by the visualizer.
 * <p>
 * When the user clicks on the canvas, if the x and y coordinates intersect with a base then the offset is updated
 * to the given base. If the mouse is hovered over a base the hovered base id is updated.
 *
 * @param canvas {@link Canvas} for use by the visualizer
 */
public void setCanvas(final Canvas canvas) {
    this.canvas = canvas;
    this.graphicsContext = canvas.getGraphicsContext2D();

    canvas.widthProperty().addListener((observable, oldValue, newValue) -> draw());
    canvas.setOnMouseClicked(event -> {
        Optional.of(rTree).ifPresent(tree -> tree.find(event.getX(), event.getY(), offsetProperty::set));
        // Do a second search as base nodes have been shifted.
        Optional.of(rTree).ifPresent(tree -> tree.find(event.getX(), event.getY(), hoveredBaseIdProperty::set));
    });
    canvas.setOnMouseMoved(event -> Optional.of(rTree)
            .ifPresent(tree -> tree.find(event.getX(), event.getY(), hoveredBaseIdProperty::set)));
    canvas.setOnMouseExited(event -> hoveredBaseIdProperty.set(-1));
}
 
开发者ID:ProgrammingLife2017,项目名称:hygene,代码行数:23,代码来源:SequenceVisualizer.java

示例3: setCanvas

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
/**
 * Set {@link Canvas} which the {@link GraphVisualizer} use to draw.
 *
 * @param canvas canvas to be used to {@link GraphVisualizer}
 */
public void setCanvas(final Canvas canvas) {
    this.canvas = canvas;
    this.graphicsContext = canvas.getGraphicsContext2D();
    this.segmentDrawingToolkit.setGraphicsContext(graphicsContext);
    this.snpDrawingToolkit.setGraphicsContext(graphicsContext);
    this.edgeDrawingToolkit.setGraphicsContext(graphicsContext);
    this.graphAnnotationVisualizer.setGraphicsContext(graphicsContext);

    canvas.setOnMouseClicked(event -> {
        selectedSegmentProperty.setValue(null);
        if (rTree == null) {
            return;
        }

        rTree.find(event.getX(), event.getY(), this::setSelectedSegment);
    });
    canvas.setOnMouseMoved(event -> {
        if (graphDimensionsCalculator.getLastScrollTime() > System.currentTimeMillis() - 100) {
            return;
        }

        hoveredSegmentProperty.set(null);
        if (rTree == null) {
            return;
        }

        rTree.find(event.getX(), event.getY(), this::setHoveredSegmentProperty);
    });
    canvas.setOnMouseExited(event -> hoveredSegmentProperty.set(null));

    graphDimensionsCalculator.setCanvasSize(canvas.getWidth(), canvas.getHeight());
    canvas.widthProperty().addListener((observable, oldValue, newValue) -> {
        graphDimensionsCalculator.setCanvasSize(newValue.doubleValue(), canvas.getHeight());
        graphAnnotationVisualizer.setCanvasWidth(newValue.doubleValue());
    });
    canvas.heightProperty().addListener((observable, oldValue, newValue) -> {
        graphDimensionsCalculator.setCanvasSize(canvas.getWidth(), newValue.doubleValue());
        segmentDrawingToolkit.setCanvasHeight(newValue.doubleValue());
        snpDrawingToolkit.setCanvasHeight(newValue.doubleValue());
    });

    graphAnnotationVisualizer.setCanvasWidth(canvas.getWidth());
    segmentDrawingToolkit.setCanvasHeight(canvas.getHeight());
    snpDrawingToolkit.setCanvasHeight(canvas.getHeight());
}
 
开发者ID:ProgrammingLife2017,项目名称:hygene,代码行数:51,代码来源:GraphVisualizer.java

示例4: start

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
@Override
public void start(Stage stage) throws Exception {
	Canvas canvas = new Canvas(CANVAS_WIDTH, CANVAS_HEIGHT);
	ImageView imgView = new ImageView();
	GraphicsContext ctx = canvas.getGraphicsContext2D();
	
	model = ModelSerializer.restoreMultiLayerNetwork(new File("minist-model.zip"));
	loader = new NativeImageLoader(28,28,1,true);
	imgView.setFitHeight(100);
	imgView.setFitWidth(100);
	ctx.setLineWidth(10);
	ctx.setLineCap(StrokeLineCap.SQUARE);
	lblResult = new Label();
	
	HBox hbBottom = new HBox(10, imgView, lblResult);
	VBox root = new VBox(5, canvas, hbBottom);
	hbBottom.setAlignment(Pos.CENTER);
	root.setAlignment(Pos.CENTER);
	
	Scene scene = new Scene(root, 520, 300);
	stage.setScene(scene);
	stage.show();
	stage.setTitle("Handwritten digits recognition");
	
	canvas.setOnMousePressed(e -> {
		ctx.setStroke(Color.WHITE);
           ctx.beginPath();
           ctx.moveTo(e.getX(), e.getY());
           ctx.stroke();
	});
	canvas.setOnMouseDragged(e -> {
		ctx.setStroke(Color.WHITE);
		ctx.lineTo(e.getX(), e.getY());
		ctx.stroke();
	});
	canvas.setOnMouseClicked(e -> {
		if (e.getButton() == MouseButton.SECONDARY) {
			clear(ctx);
		}
	});
	canvas.setOnKeyReleased(e -> {
		if(e.getCode() == KeyCode.ENTER) {
               BufferedImage scaledImg = getScaledImage(canvas);
               imgView.setImage(SwingFXUtils.toFXImage(scaledImg, null));
               try {
               	predictImage(scaledImg);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
               
		}
	});
	clear(ctx);
	canvas.requestFocus();
}
 
开发者ID:jesuino,项目名称:java-ml-projects,代码行数:56,代码来源:MnistTestFXApp.java


注:本文中的javafx.scene.canvas.Canvas.setOnMouseClicked方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。