Displaying an image!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • javatech007
    New Member
    • Nov 2007
    • 51

    Displaying an image!!

    Here is my code for displaying an image but doesnt work. It runs but displays nothing!

    [CODE=JAVA]

    import javax.swing.*;
    import java.awt.*;

    public class Frame extends JFrame
    {
    private JLabel irishrail;

    public Frame()
    {
    super("Frame");
    Container c = getContentPane( );
    setSize(600,550 );
    irishrail = new JLabel(new ImageIcon("iarn rod.bmp"));
    c.add(irishrail );
    setVisible(true );

    }

    public static void main(String args[])
    {
    Frame frame = new Frame();

    }

    }

    [/CODE]
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Sun's tutorial page for Icons: http://java.sun.com/docs/books/tutor...ents/icon.html states:

    Many Swing components, such as labels, buttons, and tabbed panes, can be decorated with an icon — a fixed-sized picture. An icon is an object that adheres to the Icon interface. Swing provides a particularly useful implementation of the Icon interface: ImageIcon, which paints an icon from a GIF, JPEG, or PNG image.
    So no go for BMP files, which aren't that platform independent anyway -- they're more of a WINDOWS artifact.

    Comment

    Working...