开发者

Can I play sound from this class into another class and control it from the other class [closed]

开发者 https://www.devze.com 2023-03-04 04:06 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_JAVA技巧 Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号