Zielony Smok

JavaFX canvas: Atrybut obwiedni ‘dashes’

Atrybut: dashes

Typ: double[]

Wartość domyślna: null

Getter: double[] getLineDashes()

Setter: void setLineDashes(double ...)

Save/restore: true

Opis: Tablica długości segmentów i przerw w linii/krawędzi przerywanej.

Atrybut obwiedni ‘dashes’

Klasa Listing25_46

Ściągnij klasę Listing25_46

package rozdzial25c;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.shape.StrokeLineCap;
import javafx.stage.Stage;

public class Listing25_46 extends Application {

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage stage) {
        try {
            Group root = new Group();
            Canvas cv = new Canvas(550, 250);
            GraphicsContext gc = cv.getGraphicsContext2D();
            //
            gc.setStroke(Color.BLUE);
            gc.setLineWidth(10);
            gc.setLineCap(StrokeLineCap.BUTT);
            //-
            gc.setLineDashes(10, 20, 10, 20);
            gc.beginPath();
            gc.moveTo(50, 50);
            gc.lineTo(500, 50);
            gc.stroke();
            //-
            gc.setLineDashes(15, 30, 15, 30);
            gc.beginPath();
            gc.moveTo(50, 100);
            gc.lineTo(500, 100);
            gc.stroke();
            //-
            double[] dashes = gc.getLineDashes();
            for(double d : dashes){
                System.out.print(d + ", ");
            }
            //-
            root.getChildren().add(cv);
            Scene scene = new Scene(root);
            stage.setScene(scene);
            stage.setTitle("Atrybut obwiedni 'dashes'");
            stage.setOnCloseRequest(e -> Platform.exit());
            stage.show();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
15.0, 30.0, 15.0, 30.0,
Atrybut obwiedni 'dashes'
Rys. 25_52. Atrybut obwiedni ‘dashes’