JavaFX Tutorial - Java Line(double startX, double startY, double endX, double endY) Constructor








Syntax

Line(double startX, double startY, double endX, double endY) constructor from Line has the following syntax.

public Line(double startX,
 double startY,
 double endX,
 double endY)

Example

In the following code shows how to use Line.Line(double startX, double startY, double endX, double endY) constructor.

/*  w w  w .ja va  2 s.  c o  m*/
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Line;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage stage) {
        VBox box = new VBox();
        final Scene scene = new Scene(box,300, 250);
        scene.setFill(null);
        
        
        Line line = new Line(0,0,0,0);
        line.setStartX(0.0f);
        line.setStartY(0.0f);
        line.setEndX(100.0f);
        line.setEndY(100.0f);


        
        box.getChildren().add(line);
        
        stage.setScene(scene);
        stage.show();
    }

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