Solved

linking two sets of code together

Posted on 2004-04-09
30
235 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
 

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
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.

 
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

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
micro services vs rest web services 16 86
nextBoolean(double p) for Random class 3 35
Way to decrease size of apk file 9 45
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

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

16 Experts available now in Live!

Get 1:1 Help Now