Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package sudoku;
  7.  
  8. import java.awt.BorderLayout;
  9. import java.awt.Dimension;
  10. import java.awt.GridLayout;
  11. import java.awt.GraphicsConfiguration;
  12. import javax.swing.JFrame;
  13. import javax.swing.JPanel;
  14. import java.awt.BorderLayout;
  15. import java.awt.Color;
  16. import java.awt.FlowLayout;
  17. import java.awt.LayoutManager;
  18. import javax.swing.BorderFactory;
  19. import javax.swing.JFrame;
  20. import javax.swing.JLabel;
  21. import javax.swing.JPanel;
  22. import javax.swing.border.Border;
  23. /**
  24. *
  25. * @author lucas.hu
  26. */
  27. public class Sudoku extends JFrame{
  28.  
  29.  
  30. public static int[][] grid =
  31. {
  32. {5, 3, 4, 6, 7, 8, 9, 1, 2},
  33. {6, 7, 2, 1, 9, 5, 3, 4, 8},
  34. {1, 9, 8, 3, 4, 2, 5, 6, 7},
  35. {8, 5, 9, 7, 6, 1, 4, 2, 3},
  36. {4, 2, 6, 8, 5, 3, 7, 9, 1},
  37. {7, 1, 3, 9, 2, 4, 8, 5, 6},
  38. {9, 6, 1, 5, 3, 7, 2, 8, 4},
  39. {2, 8, 7, 4, 1, 9, 6, 3, 5},
  40. {3, 4, 5, 2, 8, 6, 1, 7, 9}
  41. };
  42.  
  43. public static boolean[][] b_grid =
  44. {
  45. {true, true, false, false, true, false, false, false, false},
  46. {true, false, false, true, true, true, false, false, false},
  47. {false, true, true, false, false, false, false, true, false},
  48. {true, false, false, false, true, false, false, false, true},
  49. {true, false, false, true, false, true, false, false, true},
  50. {true, false, false, false, true, false, false, false, true},
  51. {false, true, false, false, false, false, true, true, false},
  52. {false, false, false, true, true, true, false, false, true},
  53. {false, false, false, false, true, false, false, true, true}
  54. };
  55.  
  56.  
  57. public Sudoku() {
  58. JPanel sudoku_frame = new JPanel();
  59. JPanel sudoku_panels = new JPanel(new BorderLayout());
  60. sudoku_frame.setLayout(new GridLayout(3,3));
  61. sudoku_panels.setLayout(new GridLayout(3,3));
  62. sudoku_panels.setSize(400,400);
  63. Border blackline = BorderFactory.createLineBorder(Color.black);
  64.  
  65. for (int row = 0; row < 3; row ++) {
  66. for (int col = 0; col < 3; col ++) {
  67. JPanel sudoku_border = new JPanel();
  68. sudoku_border.setLayout(new GridLayout(3,3));
  69. sudoku_border.setBorder(blackline);
  70. sudoku_frame.add(sudoku_border);
  71. for (int inner_row = 0; inner_row < 3; inner_row ++) {
  72. for (int inner_col = 0; inner_col < 3; inner_col ++) {
  73. Button sudoku_button = new Button(grid[row*3+inner_row][col*3+inner_col],b_grid[row*3+inner_row][col*3+inner_col]);
  74. sudoku_border.add(sudoku_button);
  75. sudoku_button.addActionListener(new TileClickHandler(this));
  76. }
  77. }
  78. }
  79. }
  80.  
  81.  
  82.  
  83.  
  84.  
  85. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  86. this.add(sudoku_frame, BorderLayout.CENTER);
  87. this.add(sudoku_panels, BorderLayout.LINE_END);
  88. this.pack();
  89. this.setVisible(true);
  90. }
  91.  
  92.  
  93.  
  94.  
  95. /**
  96. * @param args the command line arguments
  97. */
  98. public static void main(String[] args) {
  99. Sudoku game = new Sudoku();
  100. // TODO code application logic here
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement