java不显示图片

来源:百度知道 编辑:UC知道 时间:2024/05/10 09:27:22
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MyGames{
public static void main(String[] args)
{

JFrame frame =new JFrame("06");
frame.setSize(800,500);

ImageIcon img = new ImageIcon("ss.jpg");
JLabel imgLabel = new JLabel(img);
frame.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
imgLabel.setBounds(0,0,img.getIconWidth(), img.getIconHeight());

((JPanel)frame.getContentPane()).setOpaque(false);

frame.setVisible(true);
java.awt.Container container=frame.getContentPane();
ImageIcon usIcon=new ImageIcon("usIcon.gif");
ImageIcon caIcon=new ImageIcon("caIcon.gif");
ImageIcon ukIcon=new ImageIcon("ukIcon.gif");
JButton jbt1=new JButton("",usIcon);
JButton jbt2=new JButton("",caIcon);
JButton jbt3=new JButton(&qu

你的源码一定是放在一个项目中吧?现在在这个项目下新建一个普通文件夹(名称可以为images),然后你把你要加载的图片拷贝到这个文件夹。最后再把原程序中的("ss.jpg"); 改成("images/ss.jpg"); 就行了,其他图也一样。
我初学,刚好遇到这问题,自己解决了。

另外,图片的尺寸也不能太大,一般64*64,gif,png,jpg