Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bytecodeman
Created March 31, 2020 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bytecodeman/28f8a4cf1a953cbfa42ab06b056bafe2 to your computer and use it in GitHub Desktop.
Save bytecodeman/28f8a4cf1a953cbfa42ab06b056bafe2 to your computer and use it in GitHub Desktop.
CSC-112 HW5 Grid Application Solution
// Solution by A.C. Silvestri
// 3/30/2020
// CSC-112
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
public class GridApp2 extends Application {
private static final double WIDTH = 600;
private static final double HEIGHT = 600;
@Override
public void start(Stage primaryStage) {
Scene scene = new Scene(new BitGrid(WIDTH, HEIGHT), WIDTH, HEIGHT);
primaryStage.setTitle("Bit Grid Application");
primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.show();
}
/**
* The main method is only needed for the IDE with limited JavaFX support. Not
* needed for running from the command line.
*/
public static void main(String[] args) {
launch(args);
}
}
class BitGrid extends GridPane {
public BitGrid(double width, double height) {
this.setAlignment(Pos.CENTER);
this.setPadding(new Insets(10));
this.setHgap(5);
this.setVgap(5);
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
TextField tf = new TextField();
tf.setPrefColumnCount(1);
tf.setText((int) (Math.random() + 0.5) + "");
tf.setAlignment(Pos.CENTER);
tf.setFont(Font.font("Arial", FontWeight.BOLD, 20));
tf.setEditable(false);
// tf.setPrefSize(WIDTH / 10, HEIGHT / 10);
this.add(tf, j, i);
}
}
// pane.setPrefSize(WIDTH, HEIGHT);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment