當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。