Solved

cb.setActionCommand(filename); to all checkboxs

Posted on 2004-04-02
6
222 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
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:

762 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

19 Experts available now in Live!

Get 1:1 Help Now