http://pastie.org/1887099
I want to be able to control this sound from another class via a JButton from a different class.
Let's say your class playing a sound is named SoundClass, and your class containing a button is named ButtonClass.
- Pass a reference for the SoundClass object to the the ButtonClass object when initializing the ButtonClass object.
- In the ButtonClass initialization, record the SoundClass object in a private attribute of type SoundClass.
- In the button action listener, use the SoundClass reference to play the sound by calling the appropriate method.
This is a basic application of OOP and separation of concerns.
精彩评论