Results 1 to 5 of 5
  1. #1
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default How can I loop sounds in JPanel?

    I need to play background music in a JPanel. I googled everywhere but there is only examples for Applets. Can someone give me some help on how to play background music in a JPanel? thank you!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by rajkobie View Post
    I need to play background music in a JPanel. I googled everywhere but there is only examples for Applets. Can someone give me some help on how to play background music in a JPanel? thank you!
    Swing components have nothing to do with sound although there is a static method in the Applet class (you don't need to build an Applet) that can load an AudioClip for you; given that AudioClip you can play, loop or stop it. Don't implement that loading and playing logic in your JPanel itself; it takes away the distinction between controller logic and view (display) logic. As I wrote: visual components have nothing to do with sound (nor with database, nor with arrays, nothing, just displaying stuff).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    oh but how do you load the music and when do i call the methods?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by rajkobie View Post
    oh but how do you load the music and when do i call the methods?
    Loading the AudioClip is done by that method and when the music should be played is completely up to you.

    kind regards,

    Jos
    Last edited by JosAH; 04-24-2011 at 03:57 PM.
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

Similar Threads

  1. playing sounds with the javax.sound package
    By hannes in forum Advanced Java
    Replies: 8
    Last Post: 05-27-2010, 07:45 PM
  2. Combining Individual Sounds - Urgent
    By JDCAce in forum Advanced Java
    Replies: 4
    Last Post: 12-05-2008, 06:17 AM
  3. Wave Sounds
    By Doctor Cactus in forum New To Java
    Replies: 2
    Last Post: 10-22-2008, 02:44 PM
  4. Turn off sounds in Eclipse
    By gio.fou in forum Eclipse
    Replies: 2
    Last Post: 09-06-2008, 09:31 PM
  5. Sounds don't play when running applet
    By leonard in forum Java Applets
    Replies: 1
    Last Post: 08-06-2007, 09:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •