Solved

linking two sets of code together

Posted on 2004-04-09
30
244 Views
Last Modified: 2010-03-31
Hello everyone out there hope all is going well.

This following code is for an arraylist with audio files in it. They come from checkboxs being checked:
 
Code #1

for(int i = 0; i < checkboxes.length; i++) {
     checkboxes[i].setName("kp" + (i + 1));
     checkboxes[i].setActionCommand("kp" + (i + 1) + ".wav");
     choices.add(checkboxes[i]);//go through checkboxs and add them to choices
}

How could the audiofiles be streamed from the arraylist above (choices?) And then have those streams go into the code below?

Code #2

AudioInputStream asold = audioStream;
audioStream = AudioSystem.getAudioInputStream(getFormat(), asold);

private AudioInputStream getCurrentStream()
{
 return (AudioInputStream) m_audioInputStreamList.get(m_nCurrentStream);
}
0
Comment
Question by:Drop_of_Rain
  • 13
  • 10
  • 7
30 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10794860
AudioInputStream stream = AudioSystem.getAudioInputStream(new File(audiodirectory, checkbox[i].getActionCommand()))  
0
 

Author Comment

by:Drop_of_Rain
ID: 10794885
I am missing something what is:

 audiodirectory, checkbox[i].getActionCommand()))  

These audio files from the checkboxes have been rearranged by code into an arraylist. I have to get them from that arraylist because of the pattern that was created. This pattern has to be the end results.
0
 
LVL 92

Expert Comment

by:objects
ID: 10794932
so what exactly is it u need?
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:Drop_of_Rain
ID: 10794950
I need the streams coming from an arraylist named workoutArraylist!


AudioInputStream stream = AudioSystem.getAudioInputStream(new File(audiodirectory, checkbox[i].getActionCommand()))  
0
 

Author Comment

by:Drop_of_Rain
ID: 10794966
What is audiodirectory, exactly is it a name for checkbox[i].getActionCommand()))  

(audiodirectory, checkbox[i].getActionCommand()))  
0
 
LVL 92

Expert Comment

by:objects
ID: 10795021
if you've already got all your stream in an list then why do you need to bother about the checkboxes anymore?
0
 

Author Comment

by:Drop_of_Rain
ID: 10795037
I need the streams coming from an arraylist named workoutArraylist!

In it that (audiodirectory) would be (workoutArraylist)

AudioInputStream stream = AudioSystem.getAudioInputStream(new File(audiodirectory, checkbox[i].getActionCommand()))  

It was the name that had me confused
0
 
LVL 92

Expert Comment

by:objects
ID: 10795061
I'm confused, what do you have, and what do you need :)
0
 

Author Comment

by:Drop_of_Rain
ID: 10795097
I only have the files in an arraylist not the streams.

How could the audiofiles in the arraylist (choices?)  be streamed into another arraylist named workoutArraylist
And then that ayyaylist go into the code below:

AudioInputStream asold = audioStream;
audioStream = AudioSystem.getAudioInputStream(getFormat(), asold);

private AudioInputStream getCurrentStream()
{
 return (AudioInputStream) m_audioInputStreamList.get(m_nCurrentStream);
}

I can see that getting the question right is haft the battle!
0
 
LVL 92

Expert Comment

by:objects
ID: 10795388
> How could the audiofiles in the arraylist (choices?)  be streamed into another arraylist named workoutArraylist

Iterate thru the first list extracting each element and append it to second list.
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10795452
> How could the audiofiles in the arraylist (choices?)  be streamed into another arraylist named workoutArraylist

Then just call it in another array list :)

        ArrayList list1 = new ArrayList();
        list1.add(stream);    

        ArrayList list2 = new ArrayList();
        list2.add(stream);    

Hope that helps . . .
Javatm
0
 

Author Comment

by:Drop_of_Rain
ID: 10795831
Javatm.  could you explain this better to me. Doesn't a audiofile be turned into a stream?
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10796008
> Doesn't a audiofile be turned into a stream?

Yes, your question was if those audio files could be streamed into under arraylist. Thats what I showed
you on my above answer on how you can send the streamed audio files int another arraylist.

AudioInputStream stream = AudioSystem.getAudioInputStream(file);

ArrayList list1 = new ArrayList();
list1.add(stream);    

// Send to another ArrayList . . .

ArrayList list2 = new ArrayList();
list2.add(stream);    

Hope that helps . . .
Javatm
0
 

Author Comment

by:Drop_of_Rain
ID: 10796055
I think I was never understood. The arraylist that I have now is full of audiofiles not streams. I need to stream those file and store them into another arraylist so that then I could get them into this code #1.  #2 was given to me for this with actioncommands.
#3 is that code modified to be for a file only, and that file will come from the arraylist named (choices?)  from above comment?

#1
AudioInputStream asold = audioStream;
audioStream = AudioSystem.getAudioInputStream(getFormat(), asold);

private AudioInputStream getCurrentStream()
{
 return (AudioInputStream) m_audioInputStreamList.get(m_nCurrentStream);
}


#2
AudioInputStream stream = AudioSystem.getAudioInputStream(new File(audiodirectory, checkbox[i].getActionCommand()))  

#3
AudioInputStream stream = AudioSystem.getAudioInputStream(file);

0
 

Author Comment

by:Drop_of_Rain
ID: 10796125
How would the files from choices get into: AudioInputStream stream = AudioSystem.getAudioInputStream(file);

0
 
LVL 15

Expert Comment

by:Javatm
ID: 10796135
> The arraylist that I have now is full of audiofiles not streams. I need to stream those file and store them into another arraylist .

Then call the file and add it to the other ArrayList as you said :

File file1 = new File("Sample.wav");

// This is how you add file to an ArrayList . . .

ArrayList list = new ArrayList();
list.add(file1);

Hope that answers your question . . .
Friend : Javatm
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10796143
> How would the files from choices get into: AudioInputStream stream = AudioSystem.getAudioInputStream(file);

Here is the answer :

File file = new File( ((JCheckBox)choices.get(i)).getActionCommand() );
AudioInputStream stream = AudioSystem.getAudioInputStream(file);

Hope that helps . . .
Javatm
0
 
LVL 15

Accepted Solution

by:
Javatm earned 250 total points
ID: 10796147
Then if you wanna to add an array list to it its just like :

Example 1 : If you want a stream to be in another ArrayList.

  File file = new File( ((JCheckBox)choices.get(i)).getActionCommand() );
  AudioInputStream stream = AudioSystem.getAudioInputStream(file);

  ArrayList list = new ArrayList();
  list.add(stream);

Example 2 : If you want the file to directly be in another ArrayList.

  File file1 = new File( ((JCheckBox)choices.get(i)).getActionCommand() );
  ArrayList list = new ArrayList();
  list.add(file1);

Hope that answers your problem . . .
Friend : Javatm




0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
ID: 10796150
Iterator i = choices.iterator();
while (i.hasNext())
{
    JCheckBox cb = (JCheckBox) i.next();
    AudioInputStream stream = AudioSystem.getAudioInputStream(new File(audiodirectory, cb.getActionCommand()))  
    list.add(stream);
}

0
 

Author Comment

by:Drop_of_Rain
ID: 10796172
objects: Would you please explain what audiodirectory is in that code?
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10796190
> audiodirectory

Is what supposed is the directory of the file, essentially same way as I have on my previous comments :)
0
 

Author Comment

by:Drop_of_Rain
ID: 10796207
Ok I see that. I'm going to have the files in a hashmap:

public class CheckBoxesToAudioFiles {
Map checkToAudio;

public CheckBoxesToAudioFiles {
checkToAudio = new HashMap();
}

public void mapCheckboxToAudioFile(JCheckbox cb, AudioFile af) {
checkToAudio.put(cb, af);
}

public AudioFile getAudioFileForCheckbox(JCheckbox cb) {
(AudioFile)return checkToAudio.get(cb);
}

}
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10796216
> Ok I see that. I'm going to have the files in a hashmap.

Did the solution satisfied you or are you asking another question ?
0
 

Author Comment

by:Drop_of_Rain
ID: 10796232
Javatm your answer was great.

It was for objects comment
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10796246
> Javatm your answer was great.

Yes, because I was taking an overtime on the office just to solve
your question, thanks :)

Thank you for your time . . .
Friend : Javatm
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10796251
Need to go home . . .
Javatm
0
 
LVL 92

Expert Comment

by:objects
ID: 10796256
> Would you please explain what audiodirectory is in that code?

Yes its the directory that contains your audio files.

Javatm> essentially same way as I have on my previous comments :)

Actually its essentially the same as my 1st comment :)
0
 

Author Comment

by:Drop_of_Rain
ID: 10796258
Thanks for the support.
Christopher
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10796268
> Actually its essentially the same as my 1st comment :)

Sorry did'nt notice that anyways thanks for the time guys . . .
I had a very good day today.

Javatm
0
 

Author Comment

by:Drop_of_Rain
ID: 10796280
objects: > Actually its essentially the same as my 1st comment :)

On my first comment I asked:

 I am missing something what is:

 audiodirectory, checkbox[i].getActionCommand()))  

These audio files from the checkboxes have been rearranged by code into an arraylist. I have to get them from that arraylist because of the pattern that was created. This pattern has to be the end results.

I was tring to find out then.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java JRE greater than 1.6 5 63
tomcat startup error 5 65
by zero exception 10 41
sql import cannot be resolved jsp 3 23
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

809 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