Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

for loop question

Posted on 2004-04-26
12
262 Views
Last Modified: 2010-03-31
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);
               }
          }
0
Comment
Question by:Drop_of_Rain
  • 6
  • 4
12 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 125 total points
ID: 10916216
                  onOffButton.setActionCommand("kp" + (i + 1) + ".wav");

should be

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

surely?
0
 
LVL 92

Assisted Solution

by:objects
objects earned 125 total points
ID: 10916223
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);
}
0
 

Author Comment

by:Drop_of_Rain
ID: 10916246
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
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 35

Expert Comment

by:TimYates
ID: 10916260
*sigh*
0
 

Author Comment

by:Drop_of_Rain
ID: 10916398
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);
}
 
0
 

Author Comment

by:Drop_of_Rain
ID: 10934157
modulo:  Thank you very much.
0
 

Author Comment

by:Drop_of_Rain
ID: 10934179
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
0
 
LVL 35

Expert Comment

by:TimYates
ID: 10936619
Wow!!  Thanks Christopher!! :-)

I wish you all the luck in your project!!

Thanks again!!

Tim
0
 

Author Comment

by:Drop_of_Rain
ID: 10936682
You are welcome to share your knowledge with me by answering my questions any time you get a chance to.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 10936779
:-)  will do :-)
0
 

Author Comment

by:Drop_of_Rain
ID: 10936793
Thanks, I have them up all the time
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
oracle 11g 23 106
How to execute a Python program and gather return output in Java 2 40
maven disable workspace resolution 1 21
passing enum to a method 3 18
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question