Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.application.Application;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.TilePane;
- import javafx.stage.Stage;
- /**
- *
- */
- public class SudokuGUI extends Application {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- launch(args);
- }
- @Override
- public void start(Stage primaryStage) {
- primaryStage.setTitle("TilePane example");
- //Adding TilePane
- TilePane TilePane = new TilePane();
- // 2D array of TextFields with value of 5,5
- TextField[][] TF = new TextField[9][9];
- //Column is a vertical line and row is a horizontal line
- //Two FOR loops used for creating 2D array of TextFields with values row,col
- for(int row=0; row<TF.length; row++){
- for(int col=0; col<TF.length;col++){
- //Initializing 2D TextFields with values row,col
- TF[row][col] = new TextField("0");
- TF[row][col].setPrefSize(50, 50);
- TilePane.getChildren().add(TF[row][col]);
- if (row/3==0) {
- if (col/3==0) {
- TF[row][col].setAlignment(Pos.TOP_LEFT);
- }
- if (col/3==1) {
- TF[row][col].setAlignment(Pos.TOP_CENTER);
- }
- if (col/3==2) {
- TF[row][col].setAlignment(Pos.TOP_RIGHT);
- }
- }
- if (row/3==1) {
- if (col/3==0) {
- TF[row][col].setAlignment(Pos.CENTER_LEFT);
- }
- if (col/3==1) {
- TF[row][col].setAlignment(Pos.CENTER);
- }
- if (col/3==2) {
- TF[row][col].setAlignment(Pos.CENTER_RIGHT);
- }
- }
- if (row/3==2) {
- if (col/3==0) {
- TF[row][col].setAlignment(Pos.BOTTOM_LEFT);
- }
- if (col/3==1) {
- TF[row][col].setAlignment(Pos.BOTTOM_CENTER);
- }
- if (col/3==2) {
- TF[row][col].setAlignment(Pos.BOTTOM_RIGHT);
- }
- }
- }
- }
- //Adding TilePane to the scene
- Scene scene = new Scene(TilePane);
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement