Compare commits
	
		
			No commits in common. "072da881351f018152ebe1f189ee802b2ffba103" and "ffd1d4bd518f3fffea211568f2552a206ca04641" have entirely different histories.
		
	
	
		
			072da88135
			...
			ffd1d4bd51
		
	
		
					 4 changed files with 11 additions and 48 deletions
				
			
		|  | @ -1,8 +1,6 @@ | |||
| package gui; | ||||
| 
 | ||||
| import javax.swing.*; | ||||
| import javax.swing.border.Border; | ||||
| 
 | ||||
| import java.awt.*; | ||||
| import java.awt.event.*; | ||||
| 
 | ||||
|  | @ -29,42 +27,24 @@ public class SudokuView extends JFrame { | |||
|         setTitle("Sudoku Solver"); | ||||
|         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||||
|         setLayout(new BorderLayout()); | ||||
|         setIconImage(new ImageIcon("src/main/resources/sudoku.png").getImage()); | ||||
| 
 | ||||
|         initializeGrid(); | ||||
|         initializeButtons(); | ||||
| 
 | ||||
|         setMinimumSize(new Dimension(500, 500)); | ||||
|         pack(); // Resize the window to fit the components, if necessary | ||||
|         setLocationRelativeTo(null); // Center the window | ||||
|         pack(); | ||||
|         setLocationRelativeTo(null); | ||||
|     } | ||||
| 
 | ||||
|     /** Initialize the grid, called by the constructor */ | ||||
|     private void initializeGrid() { | ||||
|         grid = new JTextField[9][9]; | ||||
|         JPanel gridPanel = new JPanel(new GridLayout(9, 9)); | ||||
|         gridPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); | ||||
| 
 | ||||
|         int fontSize = 24; | ||||
|         String fontName = gridPanel.getFont().getName(); | ||||
|         Border border = BorderFactory.createLineBorder(Color.BLACK); | ||||
|         Font font = new Font(fontName, Font.BOLD, fontSize); | ||||
| 
 | ||||
|         for (int row = 0; row < 9; row++) { | ||||
|             for (int col = 0; col < 9; col++) { | ||||
|                 JTextField cell = new JTextField(2); | ||||
|                 cell.setHorizontalAlignment(JTextField.CENTER); | ||||
|                 cell.setFont(font); | ||||
|                 cell.setBorder(border); | ||||
|                 cell.setForeground(Color.BLACK); | ||||
| 
 | ||||
|                 // Set background color to gray for every third JTextField | ||||
|                 if ((row / 3 + col / 3) % 2 == 1) { | ||||
|                     cell.setBackground(Color.LIGHT_GRAY); | ||||
|                 } | ||||
| 
 | ||||
|                 grid[row][col] = cell; | ||||
|                 gridPanel.add(cell); | ||||
|                 grid[row][col] = new JTextField(2); | ||||
|                 grid[row][col].setHorizontalAlignment(JTextField.CENTER); | ||||
|                 gridPanel.add(grid[row][col]); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -20,18 +20,10 @@ public class Solver implements SudokuSolver { | |||
|         this.board = board; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * {@inheritDoc} | ||||
|      * <p> | ||||
|      * Note that this returns a copy of the board, not the actual board | ||||
|      */ | ||||
|     /** {@inheritDoc} */ | ||||
|     @Override | ||||
|     public int[][] getBoard() { | ||||
|         int[][] copy = new int[9][9]; | ||||
|         for (int row = 0; row < 9; row++) { | ||||
|             System.arraycopy(board[row], 0, copy[row], 0, 9); | ||||
|         } | ||||
|         return copy; | ||||
|         return board; | ||||
|     } | ||||
| 
 | ||||
|     /** Resets the board to all zeros */ | ||||
|  | @ -42,6 +34,7 @@ public class Solver implements SudokuSolver { | |||
|                 row[i] = 0; | ||||
|             } | ||||
|         } | ||||
|         // board = new int[9][9]; | ||||
|     } | ||||
| 
 | ||||
|     /* {@inheritDoc} */ | ||||
|  | @ -127,8 +120,8 @@ public class Solver implements SudokuSolver { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * {@inheritDoc} | ||||
|     /**  | ||||
|      * {@inheritDoc}  | ||||
|      * <p> | ||||
|      * This is <b>not</b> checked for validity | ||||
|      */ | ||||
|  |  | |||
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 8.5 KiB | 
|  | @ -17,12 +17,8 @@ class SolverTest { | |||
|         Solver solver = new Solver(); | ||||
|         int[][] board = new int[9][9]; | ||||
|         solver.setBoard(board); | ||||
| 
 | ||||
|         for (int row = 0; row < 9; row++) { | ||||
|             assertArrayEquals(board[row], solver.getBoard()[row]); | ||||
|         } | ||||
|         assertEquals(board, solver.getBoard()); | ||||
|     } | ||||
|      | ||||
| 
 | ||||
|     @Test | ||||
|     void randomizeBoardTest() { | ||||
|  | @ -32,12 +28,6 @@ class SolverTest { | |||
|         assertNotEquals(board, solver.getBoard()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     void emptyTest() { | ||||
|         Solver solver = new Solver(); | ||||
|         assertTrue(solver.solve()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     void legalTest() { | ||||
|         Solver solver = new Solver(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue