# ImageIcon option



## Caliraj (Mar 22, 2006)

Hi,
This is regarding the usage of ImageIcon. Earlier I had used Icon to add an ikon as a button.I have also come across adding image using ImageIcon as below:
ImageIcon obj=new createImageIcon("pict.jpg");

I have modified my earlier program as below:
import java.awt.event.*;
import javax.swing.*;
/*
*/
public class jbt extends JApplet implements ActionListener
{
Container c=getContentPane();
JLabel l=new JLabel("type");
JTextField t=new JTextField(10);
ImageIcon im1=createImageIcon("doggy1.gif");
JButton mb=new JButton("hi",im1);
public void init()
{
c.setLayout(new FlowLayout());
c.add(l);
c.add(t);
mb.setRolloverIcon(im1);
c.add(mb);
mb.addActionListener(this);
}
public void actionPerformed(ActionEvent a)
{
l.setText(t.getText());
}
}

*But Im getting teh following errors:*
jbt.java:7: cannot find symbol
symbol : class Container
location: class jbt
Container c=getContentPane();
^
jbt.java:10: cannot find symbol
symbol : method createImageIcon(java.lang.String)
location: class jbt
ImageIcon im1=createImageIcon("doggy1.gif");
^
jbt.java:14: cannot find symbol
symbol : class FlowLayout
location: class jbt
c.setLayout(new FlowLayout());


----------



## Chicon (Jul 29, 2004)

For errors 1 and 3, just add the following imports :

*import java.awt.Container;
import java.awt.FlowLayout;*

For error 2, just replace the line :

* ImageIcon im1=createImageIcon("doggy1.gif");*

by :

*ImageIcon im1= new ImageIcon("doggy1.gif");*


----------

