Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting images into applications

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi all
I am trying to write a program in Java and want to make it more appealing to the user by inserting images. I have been told that java has no capabilities for working with images outside applets. (getImage(directory, filename) of applet.Applet import file). Is this true? If not can you help me?
 
Java supports gif and jpg image formats for use in applications, not just applets.

you can create them as Icons by....

Icon yourPiccie = new ImageIcon("fullpathname\piccie.gif");

I have been told that Java will auto resize these things as well, but I have yet to discover how.

NB if your application is in the same directory as the image file, then you do not need to specify the full path name in the URL string.
 
You can easily display images by wrapping them in a JLabel:

import javax.swing.*;
Public class Test {
public static void main(String[] args) {
JFrame f = new JFrame("Image test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add( new JLabel( new ImageIcon("mypath\\mypic.gif") ) );
f.setSize(600,600); f.setVisible(true);
}
}

Cheers Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top