1

Welcome to you all

I have a slight problem with adding pictures ta JFrame , I'm trying to add a picture to a JLable. It works fine in the simulater, when I'm using Swing Packet in Eclipcs program. However, when I try to run the program, the image disappear completely?!!

see the pic here : http://im33.gulfup.com/yf7PH.jpg

Here is part of my code :

JLabel Pic1 = new JLabel("");
    Pic1.setIcon(new ImageIcon("C:\\Users\\Al- Yamani\\Downloads\\DSC_0243.bmp"));
    Pic1.setHorizontalAlignment(SwingConstants.CENTER);
    Pic1.setBounds(290, 11, 75, 42);
    contentPane.add(Pic1);

I do not know what is the problem?!

Also, when I try to add an icon on the title bar, it did not show as well!

setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\user\\Pictures\\gifts-icon.png"));

^^ Both codes are in my constracter body: public JFrameName(){.....}

Kozmotronik
  • 2,080
  • 3
  • 10
  • 25
Rakan 210
  • 13
  • 3
  • Please have a look at how to [add images to your Project in Java Swing](http://stackoverflow.com/a/9866659/1057230). Hope it might be able to help you in some way :-) – nIcE cOw Feb 16 '14 at 18:46

2 Answers2

2

try this ;)

JLabel lim= new JLabel();
lim.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/images.jpg")));
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Ahmed.ess
  • 265
  • 3
  • 10
  • +1, but a link to the tutorial is always nice so the OP can understand why the code should work. See [How to Use Icons](http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html) from the Swing tutorial for more information why the above might work. Note, the tutorial doesn't use the leading "/" for the file path. – camickr Feb 16 '14 at 18:32
0

public class Decompress { public static void main(String[] args) throws FileNotFoundException, IOException {

 FileOutputStream fout=new FileOutputStream("D://qq.txt");
    FileInputStream fin=new FileInputStream("D://kk.txt");
    InflaterInputStream in=new InflaterInputStream(fin);
    int i;
    while((i=in.read())!=-1)
    {
        fout.write((byte)i);
        fout.flush();

    }
    fout.close();
    fin.close();
    in.close();
}

}