Solved

for loop question

Posted on 2004-04-26
12
255 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count11 challenge 6 48
java set up 1 48
Non-recursive backtracking, using a stack 1 53
get weblogic logged in user in java 2 43
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now