Solved

cb.setActionCommand(filename); to all checkboxs

Posted on 2004-04-02
6
223 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which is the latest version of Apache Tomcatl 3 50
Way to decrease size of apk file 9 45
MySQL  on Tomcat 8 30
hibernate jars 4 0
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 “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 how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

895 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

18 Experts available now in Live!

Get 1:1 Help Now