注册 登录
编程论坛 JAVA论坛

新手:java中本地图片加载的问题

zhang2010hao 发布于 2015-10-13 22:52, 471 次点击
package chapter23;

import java.awt.BorderLayout;

import *;

import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ExampleFrame_03 extends JFrame{
    public ExampleFrame_03(){
        setVisible(true);
        setSize(100, 100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        final JDesktopPane desktopPane = new JDesktopPane();
        final JLabel backLabel = new JLabel();
        
        //URL resource = this.getClass().getResource("/nihao");
        ImageIcon icon = new ImageIcon("nihao.jpg");
        backLabel.setIcon(icon);
        backLabel.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight());
        desktopPane.add(backLabel, new Integer(Integer.MIN_VALUE));
        getContentPane().add(desktopPane, BorderLayout.CENTER);
    }
   

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
       ExampleFrame_03 f = new ExampleFrame_03();
    }
}
上面是我用eclipse写的一段代码,运行后不会出错,但是图片却没有加载出来,nihao.jpg我放在src文件夹下。怎么解决,其他的程序也遇到过这种情况
0 回复
1