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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display a JPG file in a frame

Status
Not open for further replies.

aryajur

Programmer
Jul 2, 2003
45
US
Hello,
I wanted to know how can we display a jpg image in a frame. What classes and methods can be used?
 
// you need a java book. I copy following code from a book
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ImageIconDemo
{
public static void main(String args[])
{
JFrame f = new JFrame("ImageIconDemo");
Container contentPane = f.getContentPane();
//Icon icon = new ImageIcon(".\\icons\\visa.gif");
Icon icon = new ImageIcon("1.jpg");
JLabel label = new JLabel(icon,JLabel.CENTER);
contentPane.add(label);
f.pack();
f.show();
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top