Article View: borland.public.jbuilder.java.language
Article #15808For-loops checking arrays ? Help
From: Aslak Poppe
Date: Tue, 20 Apr 1999 00:00
Date: Tue, 20 Apr 1999 00:00
85 lines
3525 bytes
3525 bytes
Good morning Newsgroup!
I was wandering if any of you experienced programmers would be kind
enough to help me with the following problem.
Im writing an aplet where i have 36 (series of 3 X 12 times) checkboxes
who are setting "flags" for my applet.
I have one two-dimentional array "Flag1" (byte Flag[ ][ ]=new
byte[12][3];) which is initiated with the byte value "0".
The checkboxes are changing these values to 1 if the checkbox is
checked. So if checkbox no.9 is checked - Flag[2][2] is set to "1".
So far so good.
The next step i to manipulate these values in an new array called
"Flag2" (byte Flag2[ ][ ]=new byte[12][3];) to these values:
According to the values in Flag 1, the values in Flag2 should change.
The point is to see if a serie of three checkboxes are checked with one,
two or three checkboxes, and which checkboxes are checked.
An example is the third serie -( Flag1[2][0]-Flag1[2][1]-Flag1[2][2]).
If only one of the three checkboxes are checked, only the first value in
the serie in Flag2 should change.
If the first value in this serie is 1- the first value in the same serie
in Flag2 should be set to 1.
If the second value in this serie is 1- the first value in the same
serie in Flag2 should be set to 2.
If the third value in this serie is 1- the first value in the same serie
in Flag2 should be set to 3.
If two of the checkboxes are checked the first 2 values in the same
serie in Flag2 should change.
If the first and second value in this serie is 1- the first value in the
same serie in Flag2 should be set to 1 and the second value to 2.
If the first and second value in this serie is 1- the first value in the
same serie in Flag2 should be set to 1 and the second value to 2.
If the first and third value in this serie is 1- the first value in the
same serie in Flag2 should be set to 1 and the second value to 3.
If the second and third value in this serie is 1- the first value in the
same serie in Flag2 should be set to 2 and the second value to 3.
If three of the checkboxes are checked, all values in the same serie in
Flag2 should change.
The first value should be set to 1, the second to 2 and the third to 3.
That was the problem.
I tried to solve this using a nested for-loop like this:
public void SetTheValuesInFlag2(){
byte i=0;
byte j=0;
byte iCount=0;
for (i=0;i<=11;i++)
{
iCount = 0;
for (j=1;i<=3;j++)
{
if (Flag1[i][j-1] == 1)
{
Flag2[i][iCount] = j;
iCount++;
}
}
}
}
I then write the values to a string and print this string in a
TextField.
The only values that are changing are the first 3 and they are not
correct.
SetTheValuesInFlag2 is run every time a value in a checkbox is changed
and the values in Flag1 is set correct (I have another check for this).
Can anyone please guide me to the right track here ???
Best regards
Aslak Poppe
aslak.poppe@radsoft.no
Internett: http://www.radsoft.no
Technical Details
Message-ID:
<371C2B96.8C9E78E9@radsoft.no>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,e327b780543d29b1,start X-Google-Attributes: gidf74b3,public From: Aslak Poppe <aslak.poppe@radsoft.no> Subject: For-loops checking arrays ? Help Date: 1999/04/20 Message-ID: <371C2B96.8C9E78E9@radsoft.no> X-Deja-AN: 468624498 Content-Transfer-Encoding: 7bit X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: RADsoft AS Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language