Monday, July 15, 2013

Drawing something on JavaFX

Example to draw something on JavaFX:

draw something on JavaFX
draw something on JavaFX


package javafx_drawsomething;

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

/**
* @web http://java-buddy.blogspot.com/
*/
public class JavaFX_DrawSomething extends Application {

Circle circle_Red, circle_Green, circle_Blue;

@Override
public void start(Stage primaryStage) {

//Create Circles
circle_Red = new Circle(50.0f, Color.RED);
circle_Red.setCursor(Cursor.HAND);

circle_Green = new Circle(50.0f, Color.GREEN);
circle_Green.setCursor(Cursor.MOVE);
circle_Green.setCenterX(150);
circle_Green.setCenterY(150);

circle_Blue = new Circle(50.0f, Color.BLUE);
circle_Blue.setCursor(Cursor.CROSSHAIR);
circle_Blue.setTranslateX(300);
circle_Blue.setTranslateY(100);

Group root = new Group();
root.getChildren().addAll(circle_Red, circle_Green, circle_Blue);

primaryStage.setResizable(false);
primaryStage.setScene(new Scene(root, 400,350));

primaryStage.setTitle("java-buddy");
primaryStage.show();
}

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


No comments:

Post a Comment