Solved

cb.setActionCommand(filename); to all checkboxs

Posted on 2004-04-02
6
224 Views
Last Modified: 2010-03-31
How could cb.setActionCommand(filename); be added to all of the 50 checkboxs through some method like below:

 for(int i = 0; i < checkboxes.length; i++) levels.add(checkboxes[i]);    //go through checkboxs and add them to levels

All the filenames start with kp  1-50 example (kp1.wav)


Total code below #2


#1
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class MyClass4 extends JPanel {

ArrayList myArrayList = new ArrayList();

// Constructor
public MyClass4() {
// JPanel myPanel = new JPanel(); // No JPanel - why do we need it? I'M a JPanel...
setLayout(new GridLayout(0,3)); // Setting MY layout...
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;
JCheckBox check = new JCheckBox("" + n);

myArrayList.add(check);
add(check); // Adding it to ME
}
}
// myPanel.setLayout(new FlowLayout()); Why would I change the layout back to FlowLayout? All hell would break loose...
// add(myPanel); Don't need it at it's ME...
}
}


#2
// Create checkboxes, and group them in a CheckboxGroup to give them
    // "radio button" behavior.
    CheckboxGroup checkbox_group = new CheckboxGroup();
    Checkbox[] checkboxes = new Checkbox[3];
    checkboxes[0] = new Checkbox("Beginner", checkbox_group, true);
    checkboxes[1] = new Checkbox("Novice", checkbox_group, false);
    checkboxes[2] = new Checkbox("Intermediate", checkbox_group, false);
    checkboxes[3] = new Checkbox("Advanced", checkbox_group, false);
    checkboxes[4] = new Checkbox("Accomplished", checkbox_group, false);

    for(int i = 0; i < checkboxes.length; i++) levels.add(checkboxes[i]);//go through checkboxs and add them to levels


0
Comment
Question by:Drop_of_Rain
  • 3
  • 3
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 10744839
Something like:

for(int i = 0; i < checkboxes.length; i++) {
      checkboxes[i].setActionCommand("kp" + (i + 1) + ".wav");
      levels.add(checkboxes[i]);//go through checkboxs and add them to levels
}      
0
 

Author Comment

by:Drop_of_Rain
ID: 10744932
CEHJ what is below was just for example. The #1 code is the code I will use. How would I name the checkboxs to add them?
 #2
// Create checkboxes, and group them in a CheckboxGroup to give them  // "radio button" behavior.
    CheckboxGroup checkbox_group = new CheckboxGroup();
    Checkbox[] checkboxes = new Checkbox[3];
    checkboxes[0] = new Checkbox("Beginner", checkbox_group, true);
    checkboxes[1] = new Checkbox("Novice", checkbox_group, false);
    checkboxes[2] = new Checkbox("Intermediate", checkbox_group, false);
    checkboxes[3] = new Checkbox("Advanced", checkbox_group, false);
    checkboxes[4] = new Checkbox("Accomplished", checkbox_group, false);

    for(int i = 0; i < checkboxes.length; i++) levels.add(checkboxes[i]);//go through checkboxs and add them to levels

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10745097
>>How would I name the checkboxs to add them?

I'm not sure i understand your question - (i thought i'd answered it)
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:Drop_of_Rain
ID: 10745187
You answered it. I was thinking that I had to name the group of checkboxs something, but I don't right. Because they are all seperate.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10745201
;-)
0
 

Author Comment

by:Drop_of_Rain
ID: 10745221
I have another simple question up if you could look at it:  help something wrong it is simple to

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20942002.html
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 53
How to parse custom JSON to POJO java 4 73
Maven Project: Hibernate Dependencies Conflict 10 22
Java string replace 11 46
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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

773 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