?
Solved

adding an audiofile to the arraylist

Posted on 2004-04-14
15
Medium Priority
?
250 Views
Last Modified: 2010-03-31
Could this code be modified to add another audiofile after each addition to dmArrayList.  Like all even numbers of the arraylist +1 Example [0] =1, [1] =2, [3]=3 etc... But when a element is removed from the dmArrayList  dmArrayList.remove(button); the added audiofile will be removed as well.


public void actionPerformed(ActionEvent e)
            {
                               
          JColoredButton button = (JColoredButton)e.getSource();
         
          if (dmArrayList.contains(button))
          {
               dmArrayList.remove(button);
               button.setDefaultColor();
          }
          else
          {
               dmArrayList.add(button);
               button.setPressedColor();
          }
         
          System.out.println(dmArrayList);
     }  
}
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
  • 9
  • 5
15 Comments
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10830333
You have JColoredButton Right.

Add a method to hold the audio file.

That way, you can get the information about the audio file for the given button.

+ It will be removed along with the button when it is removed from the arraylist.

So there is no need to have logic on even and odd index in arraylist



Regards,
Muruga
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10830360
I mean,


class JColoredButton extends JButton
{
     private Color foreground;
     private Color deafultForeground;
     private Color background;
     private Color defaultBackground;
     private String audioFileName;

     public JColoredButton(String label, Color background, Color foreground)
     {
          super(label);
          this.background = background;
          this.foreground = foreground;
          defaultBackground = getBackground();
          deafultForeground = getForeground();
     }
     
     public void setPressedColor()
     {
          setBackground(background);
          setForeground(foreground);
     }
     
     public void setDefaultColor()
     {
          setBackground(defaultBackground);
          setForeground(deafultForeground);
     }

     public void setAudioFileName(String name)
     {
           audioFileName = name;
     }

     public String getAudioFileName()
     {
           return audioFileName;
     }
}
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10830367
This way, you don't need to change your actionPerformed(ActionEvent e) method.  You can keep the method as it is.
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:Drop_of_Rain
ID: 10830563
How is this adding an audiofile between the files that go into the ayyaylist from the actionCommand.

Could this code be modified to add another audiofile after each addition to dmArrayList.  Like all even numbers of the arraylist +1 Example [0] =1, [1] =2, [3]=3 etc... But when a element is removed from the dmArrayList  dmArrayList.remove(button); the added audiofile will be removed as well.

How is this adding an audiofile between the files that go into the ayyaylist from the actionCommand.


public void setAudioFileName(String name)
     {
           audioFileName = name;
     }

     public String getAudioFileName()
     {
           return audioFileName;
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10830576
When you create the button itself, you will set the actioncommand right.  There itself, you can set your audio files too...
0
 

Author Comment

by:Drop_of_Rain
ID: 10830705
They are already set that way. I am saying that I need this to happen in the background by code. There will be no button pressed to set the audiofile. I need to have it this way, that every time a button is pressed and a audio file is sent to the arraylist that another file that is the timer between the files will then go into the arraylist. This file at times won't be the same file, but I will let an if statement take care of that.
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10830717
in the actionPerformed,

set the different audio file to the button based on your condition
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10830767
I still don't understand your Q.
Can you give an example of what you want to happen?
0
 

Author Comment

by:Drop_of_Rain
ID: 10830874
Could this code be modified to add another audiofile after each addition to dmArrayList.  Like all even numbers of the arraylist +1 Example [0] =1, [1] =2, [3]=3 etc... But when a element is removed from the dmArrayList  dmArrayList.remove(button); the added audiofile will be removed as well.


Example #1 buttom pressed = #1.wav, #2 buttom pressed = #2.wav, #3 buttom pressed = #3.wav,
#4 buttom pressed = #4.wav, #5 buttom pressed = #5.wav That is what is happening right now.

What I need is:

Example #1 buttom pressed = #1.wav, Timing audiofile added time.wav, #2 buttom pressed = #2.wav, Timing audiofile added time.wav, #3 buttom pressed = #3.wav, Timing audiofile added time.wav,  #4 buttom pressed = #4.wav, Timing audiofile added time.wav, #5 buttom pressed = #1.wav, Timing audiofile added time.wav


Example: #1 buttom pressed = #1.wav, Timing audiofile added time.wav, #2 buttom pressed = #2.wav, Timing audiofile added time.wav, #3 buttom pressed = #3.wav, Timing audiofile added time.wav,  #4 buttom pressed = #4.wav, Timing audiofile added time.wav, #5 buttom pressed = #1.wav, Timing audiofile added time.wav

NOW the user presses #3 again removing it from the arraylist and here is my problem:

Example: #1 buttom pressed = #1.wav, Timing audiofile added time.wav, #2 buttom pressed = #2.wav, Timing audiofile added time.wav, Timing audiofile added time.wav,  #4 buttom pressed = #4.wav, Timing audiofile added time.wav, #5 buttom pressed = #1.wav, Timing audiofile added time.wav

there are 2 timing files next to each other in the arraylist:

2 buttom pressed = #2.wav, Timing audiofile added time.wav, Timing audiofile added time.wav,  #4 buttom pressed = #4.wav, Timing audiofile added time.wav
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10830904
do this way


int index = arrayList.indexOf(button) ;

arrayList.remove(index); // your button
arrayList.remove(index);  // timing.wav
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10830916
but careful that

For adding the time.wav,

int index = arrayList.indexOf(button) ;

if (index > -1)
{
    arrayList.add(index+1, "timing.wav");
}



For removing...

int index = arrayList.indexOf(button) ;

if (index > -1)
{
    arrayList.remove(index); // your button
    arrayList.remove(index);  // timing.wav
}


Regards,
Muruga
0
 
LVL 9

Accepted Solution

by:
mmuruganandam earned 1400 total points
ID: 10830926
public void actionPerformed(ActionEvent e)
{
                               
          JColoredButton button = (JColoredButton)e.getSource();
         
          int index = arrayList.indexOf(button) ;

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

               button.setDefaultColor();
          }
          else
          {
               dmArrayList.add(button);
               dmArrayList.add("timing.wav");
 
               button.setPressedColor();
          }
         
          System.out.println(dmArrayList);
}  
0
 

Author Comment

by:Drop_of_Rain
ID: 10969619
That was a great answer, thanks for the support.
Christopher

P.S. Sorry about taking so long to accept this answer, I didn't bookmark it.
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10993122
Not a problem... Its my pleasure..
0
 

Author Comment

by:Drop_of_Rain
ID: 10993198
Thanks for the help and support,
Christopher
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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.
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

752 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