给你个例子参考。
package examples;
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
public class Example {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable(){
@Override public void run(){
JFrame frame = new JFrame("Example");
frame.setPreferredSize(new Dimension(800,600));
frame.getContentPane().add(new JLabel(new ImageIcon(Example.class.getResource("/images/cc.jpg"))));
frame.pack();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setIconImage(new ImageIcon(Example.class.getResource("/icon/picasa.png")).getImage());
frame.setVisible(true);
}
});
}
}
问题是图片加载得较晚,所以要稍等一下,或者先让图片加载