Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Nyttige figurer er strek (Line), rektangel (Rectangle), sirkel og ellipse (Circle og Ellipse), buesegment (Arc), polygon (Polygon), segmentert figur (Path) og tekst (Text). I tillegg er det en egen klasse for bilder (ImageView som viser et Image, som ikke er en Shape). Noen av disse er vist i eksemplet under, hvor center-regionen er fylt med et Pane-objekt med noen figurer i, med ulike grafiske effekter.

Code Block
languagejava
public class BorderPaneShapesApplication extends Application {
    
    @Override
    public void start(Stage stage) throws Exception {
        
        BorderPane root = new BorderPane(); // Root of the scene graph
        
        // Add one Text node in each surrounding region
        root.setTop(new Text("top"));
        root.setBottom(new Text("bottom"));
        root.setLeft(new Text("left"));
        root.setRight(new Text("right"));
        
        Pane shapesPane = new Pane();
        shapesPane.setPrefSize(300, 300);
        shapesPane.getChildren().addAll(
                Line line = new Line(10, 10, 100, 100),; // x1, y1, x2, y2
                line.getStrokeDashArray().setAll(10.0d, 10.0d); // dashes
        Rectangle rect = new Rectangle(150, 10, 30, 40),; // x, y, w, h
        rect.setFill(Color.BLUE);
        Ellipse ell = new Ellipse(40, 180, 40, 30),; // cx, cy, rx, ry
        ell.setStroke(Color.RED);
        new Text(180, 180, "center") // x, y, text
ell.setStrokeWidth(5);
        ell.setFill(Color.GREEN);
        Text text = new Text(180, 180, "center");
        List<String> fonts = Font.getFamilies();
        text.setFont(new Font(fonts.get((int) (Math.random() * fonts.size())), 32));
        shapesPane.getChildren().addAll(line, rect, ell, text);
        root.setCenter(shapesPane);
        
        Scene scene = new Scene(root, 500, 500);
    
        stage.setScene(scene);
        stage.setTitle("BorderPaneApplication");
        stage.show();
    }
    public static void main(String[] args) {
        launch(BorderPaneShapesApplication.class, args);
    }
}

 

Grafisk stil med CSS (Cascading Style Sheets)

...