帮忙看下为什么图片没有显示 图片目录在src 下的image 文件夹中
package com.thread; import java.awt.EventQueue; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class SleepDemo extends JFrame implements Runnable { private JLabel car; public SleepDemo(){ super(); setResizable(false); getContentPane().setLayout(null); setBounds(500,300, 300, 96); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); car=new JLabel(); ImageIcon icon =new ImageIcon(getClass().getResource("/image/1.png")); car.setIcon(icon); car.setBounds(0, 0, icon.getIconHeight(), icon.getIconWidth()); getContentPane().add(car); } public void run() { int width=getWidth(); while(true){ for(int i=0;i
ImageIcon icon =new ImageIcon(getClass().getResource("/image/1.png"));
文件路径换成磁盘路径试试。测试可以