Solved

Changing a piece of code

Posted on 2004-05-01
5
154 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 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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 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:
This video teaches viewers about errors in exception handling.

757 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

17 Experts available now in Live!

Get 1:1 Help Now