Solved

Changing a piece of code

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 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 …

728 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