Friday, February 3, 2012

JavaFX 2.0 Exercise: Draw a basic line

Draw a basic line using JavaFX 2.0
/*
* 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.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
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);

Path path = new Path();
MoveTo moveTo = new MoveTo();
moveTo.setX(50);
moveTo.setY(50);

LineTo lineTo = new LineTo();
lineTo.setX(200);
lineTo.setY(200);

path.getElements().add(moveTo);
path.getElements().add(lineTo);
path.setStrokeWidth(5);
path.setStroke(Color.BLACK);

root.getChildren().add(path);

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

No comments:

Post a Comment