Random Shape Generator
Random Shape Generator
Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ToolBar;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Shape;
import javafx.stage.Stage;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Shape Generator App");
// Create toolbars
ToolBar toolBar = new ToolBar();
shapeColorPicker = new ColorPicker(Color.BLACK);
shapeColorPicker.setOnAction(e ->
changeShapeColor(shapeColorPicker.getValue()));
backgroundColorPicker = new ColorPicker(Color.WHITE);
backgroundColorPicker.setOnAction(e ->
changeBackgroundColor(backgroundColorPicker.getValue()));
toolBar.getItems().addAll(new ColorPicker(Color.BLACK), shapeColorPicker,
new ColorPicker(Color.WHITE), backgroundColorPicker);
menuFile.getItems().addAll(clearCanvasItem, exitItem);
menuBar.getMenus().add(menuFile);
root.setTop(menuBar);
root.setBottom(toolBar);
switch (random.nextInt(3)) {
case 0:
shape = new Circle(x, y, random.nextDouble() * 50 + 10,
randomColor(random));
break;
case 1:
shape = new Rectangle(x, y, random.nextDouble() * 50 + 10,
random.nextDouble() * 50 + 10, randomColor(random));
break;
case 2:
shape = new Ellipse(x, y, random.nextDouble() * 50 + 10,
random.nextDouble() * 30 + 10, randomColor(random));
break;
default:
shape = new Circle(x, y, random.nextDouble() * 50 + 10,
randomColor(random));
break;
}
shapes.add(shape);
canvas.getChildren().add(shape);
}
}
if (selectedShape != null) {
selectedShape.setStroke(null);
}
selectedShape = clickedShape;
selectedShape.setStroke(Color.BLUE);
}