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


Java Canvas类代码示例

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


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

示例1: take

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
/**
 * Takes a snapshot of a canvas and saves it to the destination.
 * <p>
 * After the screenshot is taken it shows a dialogue to the user indicating the location of the snapshot.
 *
 * @param canvas a JavaFX {@link Canvas} object
 * @return the destination of the screenshot
 */
public String take(final Canvas canvas) {
    final WritableImage writableImage = new WritableImage((int) canvas.getWidth(), (int) canvas.getHeight());
    final WritableImage snapshot = canvas.snapshot(new SnapshotParameters(), writableImage);

    try {
        ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), FILE_FORMAT, destination);
        new InformationDialogue(
                "Snapshot taken",
                "You can find your snapshot here: " + destination.getAbsolutePath()
        ).show();
    } catch (final IOException e) {
        LOGGER.error("Snapshot could not be taken.", e);
        new ErrorDialogue(e).show();
    }

    return destination.getAbsolutePath();
}
 
开发者ID:ProgrammingLife2017,项目名称:hygene,代码行数:26,代码来源:Snapshot.java

示例2: start

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
@Override
public void start(Stage primaryStage) throws Exception {
    primaryStage.setTitle("2DTree Demo");
    Group root = new Group();
    Canvas canvas = new Canvas(XSIZE, YSIZE);
    gc = canvas.getGraphicsContext2D();
    canvas.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            gc.fillOval(e.getX(), e.getY(), 3, 3);
            double[] coords = { e.getX() / XSIZE, e.getY() / YSIZE };
            instance.insert(new HyperPoint(coords));
            instance.draw();
        }
    });

    root.getChildren().add(canvas);
    Scene sc = new Scene(root);
    primaryStage.setScene(sc);
    primaryStage.show();
}
 
开发者ID:linpc2013,项目名称:KDTree,代码行数:22,代码来源:KDTreeDemo.java

示例3: init

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
private static void init() {
    root = new Group();
    s = new Scene(root, SCENE_WIDTH, SCENE_HEIGHT);
    c = new Canvas(CANVAS_WIDTH, CANVAS_HEIGHT);
    root.getChildren().add(c);
    gc = c.getGraphicsContext2D();
    gc.setStroke(Color.BLUE);
    gc.setLineWidth(2);
    gc.setFill(Color.BLUE);
    Renderer.init();
    GameLoop.start(gc);

    //Initialize Objects
    Player p = new Player();
    setPlayer(p);
    
    //load map
    loadMap();

    //should be called at last it based on player
    EventHandler.attachEventHandlers(s);

}
 
开发者ID:ashish2199,项目名称:Aidos,代码行数:24,代码来源:Sandbox.java

示例4: initGraphics

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    getStyleClass().add("circular-plot");

    canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctx    = canvas.getGraphicsContext2D();

    ctx.setLineCap(StrokeLineCap.BUTT);

    getChildren().setAll(canvas);
}
 
开发者ID:HanSolo,项目名称:circularplot,代码行数:20,代码来源:CircularPlot.java

示例5: Framework

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
public Framework(int width, int height) {

        this.setWidth(width);
        this.setHeight(height);
        random = new Random();
        bullets = new ArrayList<>();
        tanks = new ArrayList<>();
        mines = new ArrayList<>();
        pickUps = new ArrayList<>();
        hud = new HUD(this);

        canvas = new Canvas(width, height);
        gc = canvas.getGraphicsContext2D();
        canvas.setWidth(width);
        canvas.setHeight(height);
        this.getChildren().add(canvas);

        //Create Game Loop
        gameloop = new Timeline(new KeyFrame(
                Duration.millis(16.666666666667),
                ae -> update()));
        gameloop.setCycleCount(Timeline.INDEFINITE);

        //Set SCALE to current scale of Canvas
        SCALE = this.getScaleX();

        //Make the Canvas register keystrokes
        this.addEventFilter(MouseEvent.ANY, (e) -> this.requestFocus());

        //Set Inputs
        setKeyInput();
        setMouseInput();
    }
 
开发者ID:TheBromo,项目名称:netTanks,代码行数:34,代码来源:Framework.java

示例6: initGraphics

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
private void initGraphics() {
    // prefill matrix with dotOffColor
    for (int y = 0 ; y < rows ; y++) {
        for (int x = 0 ; x < cols ; x++) {
            matrix[x][y] = dotOffColor;
        }
    }

    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 ||
        Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(preferredWidth, preferredHeight);
        }
    }

    canvas = new Canvas(preferredWidth, preferredHeight);
    ctx = canvas.getGraphicsContext2D();

    pane = new StackPane(canvas);

    getChildren().setAll(pane);
}
 
开发者ID:HanSolo,项目名称:dotmatrix,代码行数:25,代码来源:DotMatrix.java

示例7: layoutChildren

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
@Override
protected void layoutChildren()
{
	super.layoutChildren();
	final double x = this.snappedLeftInset();
	final double y = this.snappedTopInset();
	final double w = this.snapSize(this.getWidth()) - x - this.snappedRightInset();
	final double h = this.snapSize(this.getHeight()) - y - this.snappedBottomInset();

	for(Canvas canvas : this.layers)
	{
		canvas.setLayoutX(x);
		canvas.setLayoutY(y);
		canvas.setWidth(w);
		canvas.setHeight(h);
	}
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:18,代码来源:ResizeableLayeredCanvasPane.java

示例8: initGraphics

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    getStyleClass().add("sankey-plot");

    canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctx    = canvas.getGraphicsContext2D();

    getChildren().setAll(canvas);
}
 
开发者ID:HanSolo,项目名称:sankeyplot,代码行数:18,代码来源:SankeyPlot.java

示例9: initCanvas

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
/**
 * 初始化背景绘画节点
 */
protected void initCanvas() {
    canvas = new Canvas();
    //在Canvas高宽改变的时候,重新绘制
    canvas.heightProperty().addListener(observable -> {
        clearConner();
        drawConner();
    });
    canvas.widthProperty().addListener(observable -> {
        clearConner();
        drawConner();
    });

    //canvas的高宽于box的高宽绑定在一起
    canvas.widthProperty().bind(Width);
    canvas.heightProperty().bind(Height);
    getChildren().add(canvas);

    //无论Canvas接收到什么鼠标事件都传递给Box处理
    canvas.setMouseTransparent(true);
}
 
开发者ID:xfangfang,项目名称:PhotoScript,代码行数:24,代码来源:DragBox.java

示例10: HeatMap

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
public HeatMap(final double WIDTH, final double HEIGHT, ColorMapping COLOR_MAPPING, final double EVENT_RADIUS, final boolean FADE_COLORS, final double HEAT_MAP_OPACITY, final OpacityDistribution OPACITY_DISTRIBUTION) {
    super();
    SNAPSHOT_PARAMETERS.setFill(Color.TRANSPARENT);
    eventList           = new ArrayList();
    eventImages         = new HashMap<>();
    colorMapping        = COLOR_MAPPING;
    mappingGradient     = colorMapping.mapping;
    fadeColors          = FADE_COLORS;
    radius              = EVENT_RADIUS;
    opacityDistribution = OPACITY_DISTRIBUTION;
    eventImage          = createEventImage(radius, opacityDistribution);
    monochrome          = new Canvas(WIDTH, HEIGHT);
    ctx                 = monochrome.getGraphicsContext2D();
    monochromeImage     = new WritableImage((int) WIDTH, (int) HEIGHT);
    setImage(heatMap);
    setMouseTransparent(true);
    setOpacity(HEAT_MAP_OPACITY);
    registerListeners();
}
 
开发者ID:HanSolo,项目名称:worldheatmap,代码行数:20,代码来源:HeatMap.java

示例11: HeatMap

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
public HeatMap(final double WIDTH, final double HEIGHT, ColorMapping COLOR_MAPPING, final double SPOT_RADIUS, final boolean FADE_COLORS, final double HEAT_MAP_OPACITY, final OpacityDistribution OPACITY_DISTRIBUTION) {
    super();
    SNAPSHOT_PARAMETERS.setFill(Color.TRANSPARENT);
    spotList            = new ArrayList<>();
    spotImages          = new HashMap<>();
    colorMapping        = COLOR_MAPPING;
    mappingGradient     = colorMapping.getGradient();
    fadeColors          = FADE_COLORS;
    radius              = SPOT_RADIUS;
    opacityDistribution = OPACITY_DISTRIBUTION;
    spotImage           = createSpotImage(radius, opacityDistribution);
    monochrome          = new Canvas(WIDTH, HEIGHT);
    ctx                 = monochrome.getGraphicsContext2D();
    monochromeImage     = new WritableImage((int) WIDTH, (int) HEIGHT);
    setImage(heatMap);
    setMouseTransparent(true);
    setOpacity(HEAT_MAP_OPACITY);
    registerListeners();
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:20,代码来源:HeatMap.java

示例12: initGraphics

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    getStyleClass().add("coxcomb-chart");

    popup = new InfoPopup();

    canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctx    = canvas.getGraphicsContext2D();

    ctx.setLineCap(StrokeLineCap.BUTT);
    ctx.setTextBaseline(VPos.CENTER);
    ctx.setTextAlign(TextAlignment.CENTER);

    pane = new Pane(canvas);

    getChildren().setAll(pane);
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:26,代码来源:CoxcombChart.java

示例13: initGraphics

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() != 0 && getPrefHeight() != 0) {
            if (VERTICAL == getOrientation()) {
                setPrefSize(20, 250);
            } else {
                setPrefSize(250, 20);
            }
        }
    }

    getStyleClass().add("axis");

    axisCanvas = new Canvas(width, height);
    axisCtx    = axisCanvas.getGraphicsContext2D();

    pane = new Pane(axisCanvas);

    getChildren().setAll(pane);
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:22,代码来源:Axis.java

示例14: initGraphics

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
private void initGraphics() {
    // prefill matrix with pixelOffColor
    for (int y = 0 ; y < rows ; y++) {
        for (int x = 0 ; x < cols ; x++) {
            matrix[x][y] = pixelOffColor;
        }
    }

    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 ||
        Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(preferredWidth, preferredHeight);
        }
    }

    canvas = new Canvas(preferredWidth, preferredHeight);
    ctx = canvas.getGraphicsContext2D();

    getChildren().setAll(canvas);
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:23,代码来源:PixelMatrix.java

示例15: initGraphics

import javafx.scene.canvas.Canvas; //导入依赖的package包/类
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    getStyleClass().setAll("chart", "xyz-chart");

    canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctx    = canvas.getGraphicsContext2D();

    pane = new Pane(canvas);

    getChildren().setAll(pane);
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:20,代码来源:XYZPane.java


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