下面是我在一本教材上抄下来的程序,其中的图片无法正常显示
import java.awt.*;
import javax.swing.*;
public class J_Label extends JFrame
{
public J_Label()
{
super ( "Example of JLabel ");
String[]s={ "Label1:with text ",
"Label2:with text and icon ",
"Label3:with icon and text(at bottom) "
};
Icon []ic={null ,new ImageIcon( "img1.gif "),new ImageIcon( "img2.gif ")};
int []ih={0,JLabel.LEFT,JLabel.CENTER};
int []iv={0,JLabel.CENTER,JLabel.BOTTOM};
Container container=getContentPane();
container.setLayout(new FlowLayout(FlowLayout.LEFT));
for(int i=0;i <3;i++)
{ JLabel aLabel=new JLabel(s[i],ic[i],JLabel.LEFT);
if(i> 0)
{
aLabel.setHorizontalTextPosition(ih[i]);
aLabel.setVerticalTextPosition(iv[i]);
}
aLabel.setToolTipText( "this is Label "+(i+1));
container.add(aLabel);
}
setSize(250,220);
setVisible(true);
}
public static void main (String args[])
{
J_Label application=new J_Label();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
其中的
Icon []ic={null ,new ImageIcon( "img1.gif "),new ImageIcon( "img2.gif ")};其中的imag1.gif ,imag2.gif是不是得提前预存,如果是的话,存到哪个目录下?
}
------解决方案--------------------
应该放在class目录下吧,