Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

for loop question

Posted on 2004-04-26
12
Medium Priority
?
267 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
[X]
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
  • 6
  • 4
12 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 500 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 500 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

598 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