M
Munich4Me
Gast
Also danke erstmal alle für eure Hilfe bisher!
Ich hab das Applet jetzt so weit das es läuft (toll, ge?
) - nur geht es leider nicht
Kann mir einer sagen warum es nicht geht? Ich hab alles versucht - aber wenn ich auf einen Button drück macht das Programm gar nichts... Warum???
Und: Weiß einer wie ich einzelnen TextFelder eine Hintergrundfarbe geben könnte?
MfG Colin
Ich hab das Applet jetzt so weit das es läuft (toll, ge?
Code:
import java.awt.*;
import java.applet.*;
public class sudoku extends Applet
{
int x,y,z;
int i,j,k;
int t,s,r;
int a[][][]=new int[10][10][10]; //Array von [0][0][0] - [9][9][9]
//0.1.1 - 0.9.9 Ergebnis,
//1.1.1 - 9.9.9 Möglichkeiten
TextField tf[][] = new TextField[9][9]; //tf[0][0] - tf[8][8]
TextField ausgabe = new TextField(5);
Button BtLos = new Button("try...");
Button BtLoesen = new Button("do it!");
GridLayout lay = new GridLayout(10,10);
public void init()
{
setBackground(Color.blue);
setLayout(lay);
for (i=0; i<=8; i++)
{
for (j=0; j<=8; j++)
{
tf[i][j] = new TextField(1);
add(tf[i][j]);
}
}
add(BtLos);
add(ausgabe);
add(BtLoesen);
ausgabe.setEditable(false);
}
public boolean action(Event e, Object o)
{
for (i=0; i<=8; i++)
{
for (j=0; j<=8; j++)
{
if (tf[i][j] == null)
{
a[0][i][j] = 0;
}
else
{
a[0][i+1][j+1] = Integer.parseInt(tf[i][j].getText());
tf[i][j].setEditable(false);
}
for (k=1; k<=9; k++)
{
a[i][j][k] = 1;
}
}
}
if (e.target == BtLos)
{
for (x=1; x<=9; x++)
{
for (y=1; y<=9; y++)
{
for (z=1; z<=9; z++)
{
if (a[0][x][y] == z)
{
for (i=1; i<=9; i++)
{
if(z == i)
{
a[x][y][i] = 2;
}
else
{
a[x][y][i] = 0;
}
}
}
}
}
}
t=0;
do
{
for (x=1; x<=9; x++)
{
for (y=1; y<=9; y++)
{
for (z=1; z<=9; z++)
{
if (a[x][y][z] == 2)
{
for (i=1; i<=9; i++)
{
if (x == 1)
{
for (j=1; j<=9; j++)
{
if (y != j)
{
a[i][j][z] = 0;
}
}
}
}
for (j=1; j<=9; j++)
{
if (y == j)
{
for (i=1; i<=9; i++)
{
if (x != i)
{
a[i][j][z] = 0;
}
}
}
}
s=x-((x-1)%3);
r=y-((y-y)%3);
for (i=s; i<=(s+2); i++)
{
for (j=r; j<=(r+1); j++)
{
if (a[0][i][j] != a[0][x][y])
{
a[i][j][z] = 0;
}
}
}
}
}
}
}
for (x=1; x<=9; x++)
{
for (y=1; y<=9; y++)
{
for (z=1; z<=9; z++)
{
if (a[x][y][z] == 2)
{
a[0][x][y] = z;
}
i=0;
for (j=1; j<=9; j++)
{
if (a[x][y][j] == 1)
{
i=i+1;
}
}
if (i == 1)
{
for (i=1; i<=9; i++)
{
if(a[x][y][i] == 1)
{
a[x][y][i] = 2;
a[0][x][y] = i;
t++;
}
}
}
}
}
}
}
while (t!=0);
t=0;
for (i=1; i<=9; i++)
{
for (j=1; j<=9; j++)
{
if (a[0][i][j] == 0)
{
t++;
}
}
}
if (t==0)
{
ausgabe.setText("yes!");
}
else
{
ausgabe.setText("oh-oh!");
}
}
if (e.target == BtLoesen)
{
for (i=1; i<=9; i++)
{
for (j=1; j<=9; j++)
{
tf[i-1][j-1].setText(String.valueOf(a[0][i][j]));
}
}
ausgabe.setText("ready!");
}
return true;
}
}
Kann mir einer sagen warum es nicht geht? Ich hab alles versucht - aber wenn ich auf einen Button drück macht das Programm gar nichts... Warum???
Und: Weiß einer wie ich einzelnen TextFelder eine Hintergrundfarbe geben könnte?
MfG Colin