Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package sudoku;
- import java.awt.BorderLayout;
- import java.awt.Dimension;
- import java.awt.GridLayout;
- import java.awt.GraphicsConfiguration;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.FlowLayout;
- import java.awt.LayoutManager;
- import javax.swing.BorderFactory;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.border.Border;
- /**
- *
- * @author lucas.hu
- */
- public class Sudoku extends JFrame{
- public static int[][] grid =
- {
- {5, 3, 4, 6, 7, 8, 9, 1, 2},
- {6, 7, 2, 1, 9, 5, 3, 4, 8},
- {1, 9, 8, 3, 4, 2, 5, 6, 7},
- {8, 5, 9, 7, 6, 1, 4, 2, 3},
- {4, 2, 6, 8, 5, 3, 7, 9, 1},
- {7, 1, 3, 9, 2, 4, 8, 5, 6},
- {9, 6, 1, 5, 3, 7, 2, 8, 4},
- {2, 8, 7, 4, 1, 9, 6, 3, 5},
- {3, 4, 5, 2, 8, 6, 1, 7, 9}
- };
- public static boolean[][] b_grid =
- {
- {true, true, false, false, true, false, false, false, false},
- {true, false, false, true, true, true, false, false, false},
- {false, true, true, false, false, false, false, true, false},
- {true, false, false, false, true, false, false, false, true},
- {true, false, false, true, false, true, false, false, true},
- {true, false, false, false, true, false, false, false, true},
- {false, true, false, false, false, false, true, true, false},
- {false, false, false, true, true, true, false, false, true},
- {false, false, false, false, true, false, false, true, true}
- };
- public Sudoku() {
- JPanel sudoku_frame = new JPanel();
- JPanel sudoku_panels = new JPanel(new BorderLayout());
- sudoku_frame.setLayout(new GridLayout(3,3));
- sudoku_panels.setLayout(new GridLayout(3,3));
- sudoku_panels.setSize(400,400);
- Border blackline = BorderFactory.createLineBorder(Color.black);
- for (int row = 0; row < 3; row ++) {
- for (int col = 0; col < 3; col ++) {
- JPanel sudoku_border = new JPanel();
- sudoku_border.setLayout(new GridLayout(3,3));
- sudoku_border.setBorder(blackline);
- sudoku_frame.add(sudoku_border);
- for (int inner_row = 0; inner_row < 3; inner_row ++) {
- for (int inner_col = 0; inner_col < 3; inner_col ++) {
- Button sudoku_button = new Button(grid[row*3+inner_row][col*3+inner_col],b_grid[row*3+inner_row][col*3+inner_col]);
- sudoku_border.add(sudoku_button);
- sudoku_button.addActionListener(new TileClickHandler(this));
- }
- }
- }
- }
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.add(sudoku_frame, BorderLayout.CENTER);
- this.add(sudoku_panels, BorderLayout.LINE_END);
- this.pack();
- this.setVisible(true);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Sudoku game = new Sudoku();
- // TODO code application logic here
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement