my dog learned polymorphism
The moose likes Swing / AWT / SWT and the fly likes Playing Sound and displaying images!!!!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Playing Sound and displaying images!!!!!!!!" Watch "Playing Sound and displaying images!!!!!!!!" New topic

Playing Sound and displaying images!!!!!!!!

Jyothsna Sri Y
Ranch Hand

Joined: Sep 25, 2003
Posts: 35
Hello everyone,
I have a doubt regarding the way to display images and play sound files using java.
I'm importing:
the code is:
private Player p;
p = Manager.createPlayer(f.toURL());
p.addControllerListener(new EventHandler());
Will this work in linux. Are methods and classes for playing them same on all platforms??
Another question is: can someone tell me how to display a image from a file using java (in linux)?
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Yes, methods for playing sounds and displaying images should work no matter what platform you are on.

The easiest way to display an image is to create an ImageIcon and add it to a JLabel. The constructor of the ImageIcon can take an absolute or relative filename and will load the image from that file.

Java supports GIF, JPEG, and PNG (since 1.4 ) "out of the box". For other image formats you may have to use JAI (Java Advanced Imaging API) or third-party code.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Jyothsna Sri Y
Ranch Hand

Joined: Sep 25, 2003
Posts: 35
Thanks a lot Mr.Pruett. It has worked...
I agree. Here's the link:
subject: Playing Sound and displaying images!!!!!!!!
It's not a secret anymore!