Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

nested loop??

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,
Im new to programming and ive just set up a sudoku GUI in Java.
Basically my goal is to be able to solve a sudoku puzzle, but i like the graphics supported by java. I have a 9x9 array holding instances of JCombobox.

I have a set up JButton, that when pressed loops through the array and if any items have been selected in an instance of JCombobox it sets the Enable() methos to false.

Then at the moment my "solve" button loops through each row and column to see if any JComboBox has been deactivate, if so it gets the selected item from that instance of the combobox and removes the selected item from the ArrayList of every other JComboBox in that row/column.

i.e.
for(int i=0; i<9; i++)
for(int j=0; j<9; j++)
{
if(!cb_Array[i][j].isEnabled())
for(int k=0; k<9; k++)
cb_Array[i][k].avail_list((String)cb_Array[i][j].getSelectedItem());
}

searches through the rows and removes selected items form the available number list( (Integer)ArrayList ) of every other JComboBox istance in that particular row.

What Im having trouble with is doing something similar for the 3x3 squares.

If the [i][j] coordinates for the first (top left corner) 3x3 are as follows:

0,0 0,1 0,2
1,0 1,1 1,2
2,0 2,1 2,2

how do i loop throught it?
 
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Welcome to the 'ranch. This forum is for fun little puzzles. This kind of question ought to go in Java In General( beginner ).

Now, I assume you want to loop through all 9 3x3's- you already know how to loop through the example you gave.

The most self-explanatory way would just be




I think this is what you're asking.


(See Jim? I'm giving back to the community for your answers)
(Me an' Jim are on a first-name basis)
[ January 17, 2006: Message edited by: Nick George ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Who is this "Nick" person, anyway?
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
This question already appears here in JiG(b). We should continue the discussion there if necessary, but I think the OP seems to have figured it out.

Layne
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic