Link to home
Start Free TrialLog in
Avatar of Drop_of_Rain
Drop_of_Rain

asked on

for loop question

Is this correct in that loop to add kp1.wav - kp50.wav tp the buttons

onOffButton.setActionCommand("kp" + (i + 1) + ".wav");


looprow : for (int row = 0; row < 20; row++)
          {
               for (int col = 0; col < 3; col++)
               {
                    int n = (20 * col + row + 1);
                    if (n > 50)
                    {
                         break looprow;
                    }
                    JButton onOffButton = new JColoredButton("" + n, Color.green, Color.black);
                    onOffButton.addActionListener(this);
                    onOffButton.setActionCommand("kp" + (i + 1) + ".wav");
                    gridPanel.add(onOffButton);
               }
          }
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Drop_of_Rain
Drop_of_Rain

ASKER

objects
Date: 04/26/2004 12:51AM PDT
 Accepted Answer  


for (int i=1; i<=50; i++)
{
    JButton onOffButton = new JColoredButton(Integer.toString(i), Color.green, Color.black);
    onOffButton.addActionListener(this);
    onOffButton.setActionCommand("kp" + i + ".wav");
    gridPanel.add(onOffButton);
}
 
OK I can see the difference in the code, it does make more sense.

Thanks for the support,
Christopher
*sigh*
objects  TimYates answer was correct to fit the code I posted isn't that correct. I need to pay better attention. I want to be fair about this. I really try to do this.
 
onOffButton.setActionCommand("kp" + n + ".wav");



looprow : for (int row = 0; row < 20; row++)
          {
               for (int col = 0; col < 3; col++)
               {
                    int n = (20 * col + row + 1);
                    if (n > 50)
                    {
                         break looprow;
                    }
                    JButton onOffButton = new JColoredButton("" + n, Color.green, Color.black);
                    onOffButton.addActionListener(this);
                    onOffButton.setActionCommand("kp" + (i + 1) + ".wav");
                    gridPanel.add(onOffButton);
               }
          }


Comment from TimYates
Date: 04/26/2004 12:51AM PDT
 Comment  


                  onOffButton.setActionCommand("kp" + (i + 1) + ".wav");

should be

                   onOffButton.setActionCommand("kp" + n + ".wav");

surely?
 
Accepted Answer from objects
Date: 04/26/2004 12:51AM PDT
 Accepted Answer  


for (int i=1; i<=50; i++)
{
    JButton onOffButton = new JColoredButton(Integer.toString(i), Color.green, Color.black);
    onOffButton.addActionListener(this);
    onOffButton.setActionCommand("kp" + i + ".wav");
    gridPanel.add(onOffButton);
}
 
modulo:  Thank you very much.
I asked for this question to be reopened again. Because Tim Yates answered the question more precise to the code I posted. I have doubled the points to reward both of you for your answers.

Thanks for all the support,
Christopher
Wow!!  Thanks Christopher!! :-)

I wish you all the luck in your project!!

Thanks again!!

Tim
You are welcome to share your knowledge with me by answering my questions any time you get a chance to.
:-)  will do :-)
Thanks, I have them up all the time