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

cb.setActionCommand(filename); to all checkboxs

Posted on 2004-04-02
6
225 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

839 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