Wednesday, May 25, 2016

8. 2 Rectangles

Two rectangles are drawn, one with sharp edges, and the other with rounded edges.


The first rectangle is red with north west corner at 100, 100 and width and height of 100. The second rectangle, with round edges, is blue with north west corner at 200, 200 and width and height of 100.


package ex08;

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 Ex08 extends Application {
    
    @Override
    public void start(Stage primaryStage) {
        
        Rectangle rect1 = new Rectangle(
                100, 100,   // NW corner x,y
                100, 100);   // width, height
        rect1.setFill(Color.RED);
        
        Rectangle rect2 = new Rectangle(
                200, 200,   // NW corner x,y
                100, 100);   // width, height
        rect2.setFill(Color.BLUE);
        rect2.setArcHeight(50);
        rect2.setArcWidth(50);
        
        Group root = new Group();
        root.getChildren().addAll(rect1,rect2);
        
        Scene scene = new Scene(root, 400, 400, Color.GHOSTWHITE);
        
        primaryStage.setTitle("Example 8. 2 Rectangles");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

This is the output:


No comments:

Post a Comment