Sudoku Color Coded

working on a project for school to create a sudoku program, but I can’t figure how to write a certain method?
public void update(String state) {
String[] rows = state.split(“n”);
int cellsPerRow = (2 * Board.DEFAULT_ROWS – 1) * 2;
for (int r = 0; r < Board.DEFAULT_ROWS; r++) {
for (int c = 0; c < Board.DEFAULT_COLUMNS; c++) {
JTextField foo = (JTextField) getComponent(r
*cellsPerRow + c* 2);
char ch = rows[r].charAt(c);
foo.setText("" + ch);
if (ch == ' ') {
foo.setEditable(true);
foo.setBackground(Color.WHITE);
} else {
foo.setBackground(new Color(240, 240, 240));
foo.setEditable(false);
}
}
}
}
That's the code. My main problem is with the getComponent(int),
it is the only thing wrong according to Eclipse.. but I don't know how it works, if I can write the method, or implement the class with something inorder to get this method to work.
HELP!!! The sooner the better!! ^__^ Thank You!
I am not sure what Eclipse is saying about the method. As I see your code the getComponent method should be returning the JTextField at a specific row and column. Any number of possible issues could be happening:
1) The method is not returning a jtextfield
2) You are calculating the wrong integer and it cannot find the component
This method appears to be setting your board to empty strings.
If you want my help, then please provide me the following information:
1) What is the error from eclipse
2) what is the value for Board.DEFAULT_ROWS
3 what is the value for Board.DEFAULT_COLUMNS
4) what are you trying to do with cellsPerRow? (Or better still would you like a better way to reset the board?)
5) Is your board dynamic in size? for example is it typical board with the 9×9 grid or can a user pick a different size?
6) How have you defined all your jtextfields?
I will be more than happy to help you through this program. Feel free to send me an email: irishtek@yahoo.com
Double Mind for iPhone
