开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜