import javafx.scene.paint.Color; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.stage.Stage; import static javafx.application.Application.launch; /** * Use this template to create drawings in FX. Change the name of the class and * put your own name as author below. Change the size of the canvas and the * window title where marked and add your drawing code where marked. * * @author YOUR NAME */ public class TestProgram extends Application { /** * Start method (use this instead of main). * * @param stage The FX stage to draw on * @throws Exception */ @Override public void start(Stage stage) throws Exception { Group root = new Group(); Scene scene = new Scene(root); Canvas canvas = new Canvas(800, 700); // Set canvas Size in Pixels stage.setTitle("FXGraphicsTemplate"); // Set window title root.getChildren().add(canvas); stage.setScene(scene); GraphicsContext gc = canvas.getGraphicsContext2D(); // YOUR CODE STARTS HERE Shape[] a = new Shape[12]; int count = 0; for (int i = 0; i < a.length; i++){ double x1 = i * 60; double y1 = i * 50; int c1 = getRandomInteger(0, 255); int c2 = getRandomInteger(0, 255); int c3 = getRandomInteger(0, 255); Color thecolor = Color.rgb(c1,c2,c3); if (count == 0) a[i] = new Square(65,thecolor, x1,y1); else if (count == 1) a[i] = new Circle(65,thecolor, x1,y1); else if (count == 2) a[i] = new Rectangle(45,90, thecolor, x1, y1); if (a[i] instanceof Square) ((Square)a[i]).draw(gc); else if (a[i] instanceof Circle) ((Circle)a[i]).draw(gc); else if (a[i] instanceof Rectangle) ((Rectangle)a[i]).draw(gc); if (count++ == 2) count = 0; } // YOUR CODE STOPS HERE stage.show(); } /** * The actual main method that launches the app. * * @param args unused */ public static void main(String[] args) { launch(args); } /** Provides a random int between minimum and maximum,not including maximum @return minimum <= num < maximum */ public static int getRandomInteger( int minimum, int maximum) { return ((int) (Math.random() * (maximum - minimum))) + minimum; } } //Main