@@ -29,8 +29,10 @@ public SudokuView(ActionListener controller)
29
29
{
30
30
setLayout (new BorderLayout ());
31
31
32
+ //************************
33
+ // Created the Sudoku grid
34
+ //************************
32
35
JPanel sudoGrids = new JPanel ();
33
- // sudoGrids.setPreferredSize(new Dimension(100,100));
34
36
sudoGrids .setLayout (new GridLayout (9 ,9 ,0 ,0 ));
35
37
sudoGrids .setBorder (BorderFactory .createTitledBorder ("Sudoku" ));
36
38
@@ -51,13 +53,13 @@ public SudokuView(ActionListener controller)
51
53
if (j == 8 )
52
54
b [3 ] = 0 ;
53
55
if (i == 3 || i == 6 )
54
- b [0 ] = 2 ;
56
+ b [0 ] = 3 ;
55
57
if (j == 3 || j == 6 )
56
- b [1 ] = 2 ;
58
+ b [1 ] = 3 ;
57
59
if (i == 2 || i == 5 )
58
- b [2 ] = 2 ;
60
+ b [2 ] = 3 ;
59
61
if (j == 2 || j == 5 )
60
- b [3 ] = 2 ;
62
+ b [3 ] = 3 ;
61
63
grid .setBorder (BorderFactory .createMatteBorder (b [0 ], b [1 ], b [2 ], b [3 ], Color .black ));
62
64
grid .setActionCommand ("Grid" +i +j );
63
65
grid .addActionListener (controller );
@@ -69,6 +71,9 @@ public SudokuView(ActionListener controller)
69
71
70
72
add (sudoGrids , BorderLayout .CENTER );
71
73
74
+ //*********************
75
+ // Radio Button Created
76
+ //*********************
72
77
noBtn = new JRadioButton [10 ];
73
78
JPanel radios = new JPanel ();
74
79
radios .setLayout (new GridLayout (10 ,1 ));
@@ -81,19 +86,19 @@ public SudokuView(ActionListener controller)
81
86
radioBtn .setText ("Empty" );
82
87
radioBtn .setSelected (true );
83
88
}
89
+ radioBtn .addActionListener (controller );
84
90
radioBtn .setMnemonic (KeyEvent .VK_0 + i );
91
+ radioBtn .setActionCommand ("Radio " + i );
85
92
noBtnGroup .add (radioBtn );
86
93
radios .add (radioBtn );
87
94
noBtn [i ] = radioBtn ;
88
95
}
89
96
add (radios , BorderLayout .EAST );
90
97
98
+ //****************
99
+ // Button to Check
100
+ //****************
91
101
JPanel buttonsP = new JPanel ();
92
- JButton saveBtn = new JButton ();
93
- saveBtn .setText ("Save" );
94
- saveBtn .setActionCommand ("Save" );
95
- saveBtn .addActionListener (controller );
96
- buttonsP .add (saveBtn );
97
102
98
103
JButton checkBtn = new JButton ();
99
104
checkBtn .setText ("Check" );
@@ -210,6 +215,37 @@ public int getSelectedNumber()
210
215
return 0 ;
211
216
}
212
217
218
+ /**
219
+ * Change the color of cell which has the given value
220
+ * @param color The color of the cell
221
+ * @param val The value to check
222
+ */
223
+ public void changeColor (Color color , int val )
224
+ {
225
+ for (int i = 0 ; i < 9 ; i ++)
226
+ {
227
+ for (int j = 0 ; j < 9 ; j ++)
228
+ {
229
+ if (grids [i ][j ].getText ().equals ("" +val ))
230
+ grids [i ][j ].setBackground (color );
231
+ }
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Resets the color of cell to original
237
+ */
238
+ public void resetColor ()
239
+ {
240
+ for (int i = 0 ; i < 9 ; i ++)
241
+ {
242
+ for (int j = 0 ; j < 9 ; j ++)
243
+ {
244
+ grids [i ][j ].setBackground (Color .white );
245
+ }
246
+ }
247
+ }
248
+
213
249
private JButton [][] grids ;
214
250
private JRadioButton [] noBtn ;
215
251
private ButtonGroup noBtnGroup ;
0 commit comments