package litebrite;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.RowConstraints;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.scene.control.ColorPicker;
import javafx.geometry.Insets;
import javafx.scene.layout.HBox;
import javafx.scene.layout.BorderPane;
import javafx.event.*;
import javafx.scene.control.Button;
import java.awt.Paint;
/**
*
* @author narayan
*/
public class LiteBrite extends Application {
@Override
public void start(final Stage stage) throws Exception {
int rows = 50;
int columns = 50;
stage.setTitle("Enjoy your game");
GridPane grid = new GridPane();
grid.getStyleClass().add("game-grid");
for(int i = 0; i < columns; i++) {
ColumnConstraints column = new ColumnConstraints(10);
grid.getColumnConstraints().add(column);
}
for(int i = 0; i < rows; i++) {
RowConstraints row = new RowConstraints(10);
grid.getRowConstraints().add(row);
}
for (int i = 0; i < columns; i++) {
for (int j = 0; j < rows; j++) {
Pane pane = new Pane();
pane.setOnMouseReleased(e -> {
pane.getChildren().add(Anims.getAtoms(1));
});
pane.getStyleClass().add("game-grid-cell");
if (i == 0) {
pane.getStyleClass().add("first-column");
}
if (j == 0) {
pane.getStyleClass().add("first-row");
}
grid.add(pane, i, j);
}
}
HBox box = new HBox(20);
box.setPadding(new Insets(5, 5, 5, 5));
Button resetButton = new Button("Reset");
resetButton.setOnAction(new EventHandler() {
public void handle(Event t) {
System.out.println("reset pressed");
}
});
final ColorPicker colorPicker = new ColorPicker();
colorPicker.setValue(Color.CORAL);
colorPicker.setOnAction(new EventHandler() {
public void handle(Event t) {
//String color = "#" + Integer.toHexString(colorPicker.getValue().hashCode());
Color c = Color.web(String.valueOf(colorPicker.getValue()));
}
});
box.getChildren().addAll(colorPicker, resetButton);
BorderPane masterPane = new BorderPane();
masterPane.setTop(box);
masterPane.setLeft(grid);
Scene scene = new Scene(masterPane, (columns * 10)+20, (rows * 10)+55);
scene.getStylesheets().add(LiteBrite.class.getResource("resources/game.css").toExternalForm());
stage.setScene(scene);
stage.show();
}
public static class Anims {
public static Node getAtoms(final int number) {
//TODO: Add code to create a colored
System.out.println("I getAtoms");
return null;
}
}
public static void main(final String[] arguments) {
Application.launch(arguments);
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.