?
Solved

Changing a piece of code

Posted on 2004-05-01
5
Medium Priority
?
164 Views
Last Modified: 2012-05-04
Hello everyone out there, I have another question.

What is needed in this code.

Is to make this code be able to add the actioncommand of a radio button that will be set to a audiofile. The radio buttons are not created at this time. But that doesn't matter in this example.

Example:  defensiveMovesArrayList.add("timing.wav");
 

public void actionPerformed(ActionEvent e)
{
                               
          JColoredButton button = (JColoredButton)e.getSource();
         
          int index = defensiveMovesArrayList.indexOf(button) ;

          if (index > -1)
          {
               defensiveMovesArrayList.remove(index); // removal of button
               defensiveMovesArrayList.remove(index); // removal of timing.wav

               button.setDefaultColor();
          }
          else
          {
               defensiveMovesArrayList.add(button);
               defensiveMovesArrayList.add("timing.wav");
 
               button.setPressedColor();
          }
         
         }  
0
Comment
Question by:Drop_of_Rain
  • 3
  • 2
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10969434
if those radio buttons are for your timing buttons then an action listener (or defensiveMovesArrayList) are not required as only a single radio button can be selected.
0
 

Author Comment

by:Drop_of_Rain
ID: 10970343
I know that, bad code example I guess. I do not have a way that the timing audio file is getting into the list.
It needs to be done here because this defensiveMovesArrayList will be used in another section of the program.

defensiveMovesArrayList.add("timing.wav");
0
 
LVL 92

Expert Comment

by:objects
ID: 10974167
As there will only be one selected timing then I don't see a need to add it to the list.
0
 

Author Comment

by:Drop_of_Rain
ID: 10974229
Ok I just need to have it available so it can go into a list at some point. It needs to get returned in some way so it can be accessed at a later time right? I looked to see about returning at the Java website and had no luck. I must of not asked for the right information. Can you help me with this? This is asked in another question.
0
 
LVL 92

Accepted Solution

by:
objects earned 1400 total points
ID: 10974266
yes that is correct, you'd just need your timing panel to return the currently selected timing, smething like:

public class TimingPanel extends JPanel
{
   .....

  public String getSelectedTiming()
  {
     ...
  }
}
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

850 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