Solved

Changing a piece of code

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JAVA part two 5 57
Java array passed to SQL where clause 23 62
Arrays.asList  VS  ArrayList 4 45
use lov values 2 33
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

920 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

14 Experts available now in Live!

Get 1:1 Help Now