GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes to add image in prog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "to add image in prog" Watch "to add image in prog" New topic
Author

to add image in prog

mandeep singh
Greenhorn

Joined: Jul 06, 2008
Posts: 3
import javax.swing.*;
import java.awt.*;
class gf
{
JFrame f1;
JPanel p1;
JLabel pic;
JButton b1;
public gf()
{
f1=new JFrame("Yahoo.com");
f1.setSize(200,200);
f1.setVisible(true);
p1=new JPanel();
f1.getContentPane().add(p1);
Icon g1=new ImageIcon;
Icon g1=new ImageIcon("c:\\honey.JPEG");
pic=new JLabel(g1);
p1.add(pic);
b1=new JButton("accepted");
}
public static void main(String jj[])
{
gf d1=new gf();
}
}

Dear my friends i am learning java ..In my this programme i am unable to add image..2 errorscar.java:17: g1 is already defined in car()
Icon g1=new ImageIcon("c:\\honey.JPEG");and other is { or ] expected..... how it can be solve
Ted Smyth
Ranch Hand

Joined: May 28, 2008
Posts: 73
Originally posted by mandeep singh:


Dear my friends i am learning java ..In my this programme i am unable to add image..2 errorscar.java:17: g1 is already defined in car()
Icon g1=new ImageIcon("c:\\honey.JPEG");and other is { or ] expected..... how it can be solve


Use code tags please!

You declare the variable g1 twice in row. There's no need to call 2 constructors on one object.

Remove this line:


And just use this:


Edward Smith
 
GeeCON Prague 2014
 
subject: to add image in prog