Saturday, February 4, 2012

JavaFX 2.0 Exercise: Draw Circle and Ellipse

JavaFX 2.0: Draw Circle and Ellipse
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javafx_exdraw;

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

/**
*
* @author erix7
*/
public class JavaFX_exDraw extends Application {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("java-buddy.blogspot.com");
Group root = new Group();
Scene scene = new Scene(root, 400, 300, Color.WHITE);

Ellipse circle = EllipseBuilder.create()
.centerX(100)
.centerY(100)
.radiusX(30)
.radiusY(30)
.strokeWidth(3)
.stroke(Color.BLACK)
.fill(Color.BLUE)
.build();

Ellipse ellipse = EllipseBuilder.create()
.centerX(250)
.centerY(200)
.radiusX(100)
.radiusY(75)
.strokeWidth(3)
.stroke(Color.BLACK)
.fill(Color.WHITE)
.build();

root.getChildren().add(circle);
root.getChildren().add(ellipse);

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

No comments:

Post a Comment