Solved

cb.setActionCommand(filename); to all checkboxs

Posted on 2004-04-02
6
226 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
[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
  • 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
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!

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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
hibernate example using maven 12 77
runtime exception 2 50
Java 8 to Java 6 8 32
Github api to fetch the number of collaborators in a git repo 1 25
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

740 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