Class Polygon
could be used.
Here is a program that draws a solid triangle. The three vertices of the triangle are
Class Triangle
extends Group
.
The class contains a single Polygon
.
If all you wanted was one triangle you could just add
a Polygon
to a Pane
and put it in the scene graph in start()
.
But more will be done with our Triangle
.
import javafx.stage.*; import javafx.scene.*; import javafx.scene.shape.*; import javafx.scene.paint.*; class Triangle extends Group { Triangle( Color color, double x0, double y0, double x1, double y1, double x2, double y2 ) { Polygon tri = new Polygon( x0, y0, x1, y1, x2, y2 ); tri.setFill( color ); getChildren().add( tri ); } } public class DrawTriangle extends Application { public void start(Stage stage) { double sceneWidth=200, sceneHeight=200 ; double x0=0, y0=sceneHeight, x1=sceneWidth/2, y1=0, x2= sceneWidth, y2=sceneHeight; Triangle solid = new Triangle( Color.BLUE, x0, y0, x1, y1, x2, y2 ); Scene scene = new Scene( solid, sceneWidth, sceneHeight, Color.SNOW ); stage.setTitle("Solid Triangle"); stage.setScene(scene); stage.show(); } }
Could several Polygon
objects be part of our Triangle
group?