Mad
any ideas thoughts etc. would be greatly apppreciated!!!!!!
oh if you are not familiar with the Sudoku game check out this link:
http://www.eddaardvark.co.uk/sudokusolver.html
Here is my code so far:
- Code: Select all
import java.applet.Applet;
import java.awt.TextArea;
import java.awt.Color;
import java.awt.TextComponent;
import java.awt.event.TextListener;
import java.awt.event.TextEvent;
import java.awt.GridLayout;
public class Sudoku extends Applet {
TextArea [][] numbers = new TextArea[9][9];
public void init(){
this.setLayout(new GridLayout(9,9));
for (int i=0; i<numbers.length; i++){
for (int j=0; j<numbers[i].length; j++){
numbers[i][j] = new TextArea();
this.add(numbers[i][j]);
numbers[i][j].addTextListener(new Performer(i,j));
}
}
}
class Performer implements TextListener {
int row;
int col;
Performer(int r, int c){
row = r;
col = c;
}
/*
* bogus returns false if there is no problem putting a number
* at a position
*/
public boolean bogus(int row, int col, String snum){
// scan row to see if there's another number the same
for (int i=0; i<numbers[row].length; i++){
if (i != col && snum.equals(numbers[row][i].getText())){
return true;
}
}
// scan col to see if there's another number the same
for (int i=0; i<numbers[row].length; i++){
if (i != row && snum.equals(numbers[i][col].getText())){
return true;
}
}
// scan the box to see ...
int [] istartA = {0,0,0,3,3,3,6,6,6};
int istart =istartA[row];
int [] jstartA = {0,0,0,3,3,3,6,6,6};
int jstart =jstartA[col];
for (int i=istart; i<=istart+2; i++){
for (int j=jstart; j<=jstart+2; j++){
System.out.print("rc="+row+","+col+"ij="+i+","+j);
System.out.println(" "+snum+","+numbers[i][j].getText());
if (i!=row && numbers[i][j].getText().equals(snum)){
return true;
// numbers[row][col].setText("");
}
}
}
return false;
}
public void textValueChanged(TextEvent t ){
// get the value which just changed
String snum = numbers[row][col].getText();
if (bogus(row,col,snum)){
numbers[row][col].setBackground(Color.RED);
}
// don't paint blanks red!
if (snum.equals("")) {
numbers[row][col].setBackground(Color.WHITE);
}
if (snum.equals(null)){
}
// check every blank block, and
//if it has only one
// possible answer, turn the background green.
//if it has no possible answer
// turn the background red
}
}
}


