Solved

Changing a piece of code

Posted on 2004-05-01
5
160 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
[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
  • 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 350 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

Technology Partners: 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!

Question has a verified solution.

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

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 …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
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…

730 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