import java.awt.EventQueue;
import java.awt.Image;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
public class IconFrame extends JFrame {
public IconFrame init(){
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(300,200);
try {
Image image = ImageIO.read(new File("INPUT YOUR IMAGE FILE NAME HERE!"));
this.setIconImage(image);
} catch (Exception e) {
e.printStackTrace();
}
return this;
}
public static void main(String[] args){
EventQueue.invokeLater(new Runnable(){
public void run(){
new IconFrame().init().setVisible(true);
}
});
}
}
this.setIconImage(Toolkit.getDefaultToolkit().getImage(MyFrame.class.getResource("imgs/icon.gif")));这是一种方法,但不是最佳,我当初学Java用的就是这个。
setIconImage()