Results 1 to 3 of 3
  1. #1
    hitmen is offline Member
    Join Date
    Oct 2008
    Posts
    58
    Rep Power
    0

    Default Adding wav sound into a JLabel.

    Hi! This is my code. Apparently there is something wrong as my something.wav cannot be detected. Can anyone alter the code for me? BTW, I am adding the sound into JPanel and not JLabel.

    Clip clip;
    AudioInputStream sam;
    File file = new File("PBSS.wav");
    try{
    sam = AudioSystem.getAudioInputStream(file);
    //next part
    clip=AudioSystem.getClip();
    clip.open(sam);
    }
    catch (IOException ioe ){ioe.getMessage();}
    catch (UnsupportedAudioFileException uafe){uafe.getMessage();}
    //next part
    catch (LineUnavailableException lue){lue.getMessage();}
    catch (SecurityException se){se.getMessage();}
    catch (IllegalArgumentException iae) {iae.getMessage();}
    }

    // I need help as PBSS.wav is undetectable at runtime. It is stored in the package resources.
    Last edited by hitmen; 02-16-2009 at 05:39 AM.

  2. #2
    hitmen is offline Member
    Join Date
    Oct 2008
    Posts
    58
    Rep Power
    0

    Default

    It says

    File file = new File(
    C:\Users\C\Documents\NetBeansProjects\aboutpage\sr c\learn\resources\PBSS.wav)

    Netbeans will say it is not a statement so what should I do?

  3. #3
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    In Java, the '\' character is the escape character. If you replace every usage of it in your file path with '\\', it should work.

    Also in Java, you can use '/' in file paths instead of '\' to avoid that problem. This works on all platforms, including Windows.

Similar Threads

  1. jLabel
    By Matty in forum AWT / Swing
    Replies: 3
    Last Post: 09-22-2008, 10:22 PM
  2. GUI - JLabel
    By Azndaddy in forum New To Java
    Replies: 8
    Last Post: 05-02-2008, 07:03 AM
  3. Problem in adding sound.
    By shanky_sanks in forum Java Applets
    Replies: 6
    Last Post: 03-29-2008, 08:37 PM
  4. JLabel
    By Jack in forum AWT / Swing
    Replies: 2
    Last Post: 07-02-2007, 01:55 PM
  5. JLabel
    By Freddie in forum AWT / Swing
    Replies: 2
    Last Post: 05-29-2007, 02:19 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
  •