Applet sudoku
Hello, I was wondering if anyone can help me. I am designing a sudoku game for a project in uni and im struggling to use applets. The difficulty im having now is that i have paint drawing each small grid(as a colored area in the background), but I am using a for loop to create each individual jtextfield for input and within paint it causes issues. Is their a way I can create the painted background for the smaller grids and then add the jtextfields over this outside of paint?
Also any links for good applet tutorials welcome,
cheers in advance
MM
[582 byte] By [
fulmont99a] at [2007-11-26 17:49:42]

ok, im lost again:)
This is the code i have to give you an idea what im attempting to do, is this the completely wrong way to do this?
public class sudoku extends Applet {
int row[];
int column[];
JTextField game[][];
JTextField f;
JTextField n;
JButton start;
public void init() {
game=new JTextField[9][9];
}
public void paint(Graphics g)
{
super.paint(g);
g.setColor(new Color(185, 220, 250));
g.fillRect(0,0,115,115);
g.fillRect(235,0,115,115);
g.fillRect(115,115,120,120);
g.fillRect(0,235,115,115);
g.fillRect(235,235,115,115);
g.setColor(new Color(127, 203, 250));
g.fillRect(115,0,120,115);
g.fillRect(0,115,115,120);
g.fillRect(235,115,115,120);
g.fillRect(115,235,120,115);
setLayout(null);
int row=5;
int col=5;
int watcher=0;
for(int i=0; i<game.length;i++)
{
for(int j=0; j><game.length; j++)
{
if(watcher==8)
{
game[i][j]=new JTextField(""+ Integer.toString(i) +""+ Integer.toString(j) +"");
game[i][j].setBounds(row,col,20,20);
add(game[i][j]);
row=5;
col=col+40;
watcher=0;
System.out.println(" watcher equal 9 "+watcher+" i="+i+" j="+j+" row="+row+" col="+col);
}
else
{
game[i][j]=new JTextField();
game[i][j].setBounds(row,col,20,20);
add(game[i][j]);
row=row+40;
watcher++;
//System.out.println(" watcher not equal 9 "+watcher+" i="+i+" j="+j+" row="+row+" col="+col);
//System.out.println("minigrid=" +minigrid(i,j));
}
}
}
start=new JButton("Start");
start.setBounds(1,370,100,30);
add(start);
}
Thanks again all!!!
MM>
Thanks Sabre,
I am going to try using SpringLayout() to arange the elements, I will have to read some tutorials on that, especially how to define each minigrid.
I have moved the textfield initialisation to the init() section, so should i create a panel and add them to this. Can i still use the image i have drawn as a background? Mayube i wont have to if i can find another way to display each minigrid.
I have also changed to JApplet:)
Ill keep working at it here, thanks so much for your help!
> I am going to try using SpringLayout() to arange the
> elements, I will have to read some tutorials on that,
> especially how to define each minigrid.
The obvious layout to use it GridLayout! It lays out components in a regular grid with ALL components being made the same size.
> I have moved the textfield initialisation to the
> init() section, so should i create a panel and add
> them to this.
Yes, then you can set the panel to use a GridLayout!
> Can i still use the image i have drawn
> as a background?
I don't see why you use an image!
> Mayube i wont have to if i can find
> another way to display each minigrid.
Did you look at the thread a I referenced in reply #1 ?