Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. import javafx.application.Application;
  2. import javafx.geometry.Pos;
  3. import javafx.scene.Scene;
  4. import javafx.scene.control.TextField;
  5. import javafx.scene.layout.TilePane;
  6. import javafx.stage.Stage;
  7.  
  8. /**
  9. *
  10. */
  11. public class SudokuGUI extends Application {
  12.  
  13. /**
  14. * @param args the command line arguments
  15. */
  16. public static void main(String[] args) {
  17. launch(args);
  18. }
  19.  
  20. @Override
  21. public void start(Stage primaryStage) {
  22. primaryStage.setTitle("TilePane example");
  23.  
  24. //Adding TilePane
  25. TilePane TilePane = new TilePane();
  26.  
  27. // 2D array of TextFields with value of 5,5
  28. TextField[][] TF = new TextField[9][9];
  29.  
  30. //Column is a vertical line and row is a horizontal line
  31. //Two FOR loops used for creating 2D array of TextFields with values row,col
  32. for(int row=0; row<TF.length; row++){
  33. for(int col=0; col<TF.length;col++){
  34.  
  35. //Initializing 2D TextFields with values row,col
  36. TF[row][col] = new TextField("0");
  37. TF[row][col].setPrefSize(50, 50);
  38. TilePane.getChildren().add(TF[row][col]);
  39.  
  40. if (row/3==0) {
  41.  
  42. if (col/3==0) {
  43. TF[row][col].setAlignment(Pos.TOP_LEFT);
  44. }
  45.  
  46. if (col/3==1) {
  47. TF[row][col].setAlignment(Pos.TOP_CENTER);
  48. }
  49.  
  50. if (col/3==2) {
  51. TF[row][col].setAlignment(Pos.TOP_RIGHT);
  52. }
  53.  
  54. }
  55.  
  56. if (row/3==1) {
  57.  
  58. if (col/3==0) {
  59. TF[row][col].setAlignment(Pos.CENTER_LEFT);
  60. }
  61.  
  62. if (col/3==1) {
  63. TF[row][col].setAlignment(Pos.CENTER);
  64. }
  65.  
  66. if (col/3==2) {
  67. TF[row][col].setAlignment(Pos.CENTER_RIGHT);
  68. }
  69.  
  70. }
  71.  
  72. if (row/3==2) {
  73.  
  74. if (col/3==0) {
  75. TF[row][col].setAlignment(Pos.BOTTOM_LEFT);
  76. }
  77.  
  78. if (col/3==1) {
  79. TF[row][col].setAlignment(Pos.BOTTOM_CENTER);
  80. }
  81.  
  82. if (col/3==2) {
  83. TF[row][col].setAlignment(Pos.BOTTOM_RIGHT);
  84. }
  85.  
  86. }
  87.  
  88.  
  89. }
  90. }
  91.  
  92. //Adding TilePane to the scene
  93. Scene scene = new Scene(TilePane);
  94. primaryStage.setScene(scene);
  95. primaryStage.show();
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement