Thursday, April 5, 2012

JavaFX 2: Apply transform of rotate

JavaFX 2: Apply transform of rotate

package javafx_transform;

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

/**
*
* @web http://java-buddy.blogspot.com/
*/
public class JavaFX_Transform 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, 300, 250);

Rectangle rect1 = new Rectangle(100, 100, Color.BLUE); //without rotate
Rectangle rect2 = new Rectangle(100, 100, Color.RED); //with rotate 30 degree
rect2.getTransforms().add(new Rotate(30, 0, 0));

root.getChildren().add(rect1);
root.getChildren().add(rect2);
primaryStage.setScene(scene);
primaryStage.show();
}
}


No comments:

Post a Comment