wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Playing Sound and displaying images!!!!!!!!" Watch "Playing Sound and displaying images!!!!!!!!" New topic
Author

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:
import javax.media.*;
the code is:
private Player p;
p = Manager.createPlayer(f.toURL());
p.addControllerListener(new EventHandler());
p.start();
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)?
Thanks,
Jyothsna.
Nathan Pruett
Bartender

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.


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

Joined: Sep 25, 2003
Posts: 35
Hi,
Thanks a lot Mr.Pruett. It has worked...
cheers
Jyothsna.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Playing Sound and displaying images!!!!!!!!
 
Similar Threads
how to add sound on clicking button in a panel
getting Java Graphics from MacOSX via ssh on a LinuxBox
JMF Audio Sample Rendering
sounds
CD is Playing but sound not coming out