Solved

How to access a audio file from these checkboxs

Posted on 2004-03-27
10
217 Views
Last Modified: 2010-03-31
This code was used to create the layout, but how would I be able to access a checkbox from this code when audio files and checboxs are in a hashmap. (code included)


import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class MyClass extends JPanel {
 
  ArrayList myArrayList = new ArrayList();

  // Constructor
  public MyClass() {
    JPanel myPanel = new JPanel();
    myPanel.setLayout(new GridLayout(0,3));
    for (int row=0; row<20; row++) {
      for(int col=0; col<3; col++) {
        /* choose one of these numbering */
        int labelint = 20 * col + row;
        //int labelint = col + 3 * row;
        JCheckBox check = new JCheckBox("" + labelint);
        myArrayList.add(check);
        myPanel.add(check);
      }
    }
    this.setLayout(new FlowLayout());
    this.add(myPanel);
  }

  private static final String FRAME_TITLE = "My Class";
  private static final int FRAME_WIDTH  = 150;
  private static final int FRAME_HEIGHT = 300;

  public void showFrame() {
    JFrame myFrame = new JFrame(FRAME_TITLE) {
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); }
      }
    };
    myFrame.getContentPane().add(this, BorderLayout.CENTER);
    myFrame.pack();
    myFrame.setSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
    myFrame.setVisible(true);
  }

  public static void main(String[] args) {
    MyClass myMyClass = new MyClass();
    myMyClass.showFrame();
  }

}

//checkbox to 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
Comment
Question by:Drop_of_Rain
  • 6
  • 4
10 Comments
 
LVL 15

Expert Comment

by:Javatm
ID: 10697647
You need 1st to know how to play music in Java consider this example :
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20641397.html

Hope that helps . . .
Javatm
0
 

Author Comment

by:Drop_of_Rain
ID: 10697669
I have that code that was easy. I even have a player in my FileChooser. I wasn't clear I need to know how to access the checkboxs in MyClass. Code below

public MyClass() {
    JPanel myPanel = new JPanel();
    myPanel.setLayout(new GridLayout(0,3));
    for (int row=0; row<20; row++) {
      for(int col=0; col<3; col++) {
        /* choose one of these numbering */
        int labelint = 20 * col + row;
        //int labelint = col + 3 * row;
        JCheckBox check = new JCheckBox("" + labelint);
        myArrayList.add(check);
        myPanel.add(check);
      }
    }
0
 
LVL 15

Accepted Solution

by:
Javatm earned 450 total points
ID: 10697747
I'll check it tonight, got to go now. I'll be back tommorow.

Try this 1st :

CheckBoxesToAudioFiles x = new CheckBoxesToAudioFiles();

Or new CheckBoxesToAudioFiles();

Remember that the class CheckBoxesToAudioFiles should be either in
the same Class or else you need to import it to use the codes above.

Thanks again . . .
Javatm
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10697784
> Or else you need to import it to use the codes above.

While I'm not arround read this to help you use package and importing it :
http://java.sun.com/docs/books/tutorial/java/interpack/packages.html

Hope that helps . . .
Javatm
0
 

Author Comment

by:Drop_of_Rain
ID: 10698602
Are the numbers generated from the code below, the names for the checkboxs in the arraylist. I know this is a dump question.

public class MyClass extends JPanel {
 
  ArrayList myArrayList = new ArrayList();

  // Constructor
  public MyClass() {
    JPanel myPanel = new JPanel();
    myPanel.setLayout(new GridLayout(0,3));
    for (int row=0; row<20; row++) {
      for(int col=0; col<3; col++) {
        /* choose one of these numbering */
        int labelint = 20 * col + row;
        //int labelint = col + 3 * row;
        JCheckBox check = new JCheckBox("" + labelint);
        myArrayList.add(check);
        myPanel.add(check);
      }
    }
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 15

Expert Comment

by:Javatm
ID: 10700322
> Are the numbers generated from the code below, the names for the checkboxs in the arraylist.

Yes, comming from :

for (int row=0; row<20; row++) {
      for(int col=0; col<3; col++) {
        /* choose one of these numbering */
        int labelint = 20 * col + row;
        // int labelint = col + 3 * row;
        JCheckBox check = new JCheckBox("" + labelint);
        myArrayList.add(check);
        myPanel.add(check);
      }
    }
0
 

Author Comment

by:Drop_of_Rain
ID: 10701439
Could someone please explain how this code, or better yet write a small program that uses it in both directions to help me understand this. I know this is a great piece of code for what i am trying to accomplish, I just don't get it. HELP PLEASE


public class MyClass extends JPanel {
 
  ArrayList myArrayList = new ArrayList();

  // Constructor
  public MyClass() {
    JPanel myPanel = new JPanel();
    myPanel.setLayout(new GridLayout(0,3));
    for (int row=0; row<20; row++) {
      for(int col=0; col<3; col++) {
        /* choose one of these numbering */
        int labelint = 20 * col + row;
        //int labelint = col + 3 * row;
        JCheckBox check = new JCheckBox("" + labelint);
        myArrayList.add(check);
        myPanel.add(check);
      }
    }



//checkbox to 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);
}

OK, so how would I link the checboxs in MyArrayList to the hashmap where the audio files and the checkboxs are linked together. Or would it be better to let go of the hashmap and use seperate arraylist for each checkbox group.
I ask this now because this came from another question. Please read to understand what I am trying to ask and where my thoughts are going now.

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20920844.html

In that question I stated that 5 arraylist would be using the same audio files. What I am thinking know if I made seperate unique audio files then I wouldn't have this problem, if it is a problem. It just looks that way to me.
My problem is in understanding the hashmap. I read up on it but that just sliped right though my consciousness. So if some one could explain it in layman terms to me so I can get it, then I can move on with this project.

Another problem is I get micro focused until I resolve it in some way. I hope that not to many of you have this infliction.

Thanks for all of your help.

Rgds,
Christopher
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10701780
Okey honestly saying I dont understand your question here specially that your codes above produces errors
because of some codes or file missing, if you dont mind can you just explain it all to me one by one so
that I can help you w/ your problem, thanks.

Friend : Javatm
0
 

Author Comment

by:Drop_of_Rain
ID: 10702014
The program I am writing but not without all of your help and others.

It will be a training program that will be customizable. It will have many different checkboxs that will triger random number generators, pattern sequencers and all the different sections of the workouts. Each section will have a checkbox for each part of the workout. Any or all parts of a workout can be choosen. Each checkbox group (section) will then be passed to a number mixing class that will create patterns. Example (1234,4321,4123,3421, etc in groups of 3,4 or 5 depending what section because of the number of parts in that section. Another class will then choose different 4 number groups and then pass 1 number at a time into an arraylist. These single numbers will corespond will an audio file. Thes audio files the need to be collected from different sections and made into one new concatenated WAVE audio file. All the concatenated audio files from all created workouts will then be burned onto a CD for the trainee to use.

I have increased the points because this just got into a big question. Thanks for helping
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10710273
Hmp.

This problem of yours is some what hard :) as what I can see you need to specialize your self 1st in this field
of sound programming. I've created sound application before but to tell you the truth, it really gave me a pane
in the head. So if I where you why not get a book about sound programming in Java and study it.

I played music before in Java but it wont play if the sound is so big so I have to strip the quality of the sound
before I can get it to play, either ways you can use JMF to be able to maximize your program :

http://java.sun.com/products/java-media/jmf/

This could also help : http://www.jsresources.org/

Hope that helps . . .
Javatm
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…

744 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

10 Experts available now in Live!

Get 1:1 Help Now