codestory

Die Anleitung zu JavaFX Rectangle und Ellipse

  1. JavaFX Rectangle
  2. Der Rund-eckige Rechteck
  3. JavaFX Ellipse
  4. Die Effekte

1. JavaFX Rectangle

Class Rectangle ist Class für die Unterzeichnung eines Rechteck wie die Class Line, Circle wird er vom Class Shape ausgeweitert
RectangleDemo.java
package org.o7planning.javafx.rectangle;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class RectangleDemo extends Application {

    @Override
    public void start(Stage primaryStage) {

        Rectangle rectangle = new Rectangle();
        rectangle.setX(20);
        rectangle.setY(50);
        rectangle.setWidth(200);
        rectangle.setHeight(150);
        rectangle.setFill(Color.BISQUE);

        Group root = new Group();
        root.getChildren().add(rectangle);

        Scene scene = new Scene(root, 400, 250, Color.WHITE);
        primaryStage.setTitle("JavaFX Rectangle (o7planning.org)");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

}

2. Der Rund-eckige Rechteck

RectangleRoundedCornerDemo.java
package org.o7planning.javafx.rectangle;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class RectangleRoundedCornerDemo extends Application {

    @Override
    public void start(Stage primaryStage) {

        Rectangle rectangle = new Rectangle();
        rectangle.setX(80);
        rectangle.setY(50);
        rectangle.setWidth(200);
        rectangle.setHeight(150);
        rectangle.setFill(Color.CADETBLUE);
       
        rectangle.setArcHeight(105);
        rectangle.setArcWidth(50);

        Group root = new Group();
        root.getChildren().add(rectangle);

        Scene scene = new Scene(root, 400, 250, Color.WHITE);
        primaryStage.setTitle("JavaFX Rectangle (o7planning.org)");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

}

3. JavaFX Ellipse

EllipseDemo.java
package org.o7planning.javafx.ellipse;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.stage.Stage;

public class EllipseDemo extends Application {

   @Override
   public void start(Stage primaryStage) {

       Group root = new Group();

       Ellipse ellipse = new Ellipse();
       ellipse.setCenterX(180.0f);
       ellipse.setCenterY(150.0f);

       // Radius X
       ellipse.setRadiusX(120.0f);

       // Radius Y
       ellipse.setRadiusY(80.0f);

       // Fill color.
       ellipse.setFill(Color.CORNFLOWERBLUE);

       root.getChildren().add(ellipse);

       Scene scene = new Scene(root, 400, 250);

       primaryStage.setTitle("JavaFX Ellipse (o7planning.org)");

       primaryStage.setScene(scene);
       primaryStage.show();
   }

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

}

4. Die Effekte

Beispiel . Die Shape rotieren
EllipseDemo2.java
package org.o7planning.javafx.ellipse;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.stage.Stage;

public class EllipseDemo2 extends Application {

    @Override
    public void start(Stage primaryStage) {

        Group root = new Group();

        Ellipse ellipse = new Ellipse();
        ellipse.setCenterX(180.0f);
        ellipse.setCenterY(150.0f);

        // Radius X
        ellipse.setRadiusX(120.0f);

        // Radius Y
        ellipse.setRadiusY(80.0f);

        // Fill color.
        ellipse.setFill(Color.CORNFLOWERBLUE);
       
        // Rotate 30 degrees
        ellipse.setRotate(30);

        root.getChildren().add(ellipse);

        Scene scene = new Scene(root, 400, 250);

        primaryStage.setTitle("JavaFX Ellipse (o7planning.org)");

        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

}

Die Anleitungen JavaFX

Show More