更改JFram标题栏图标
方式一: package com.swing.test; import javax.swing.ImageIcon; import javax.swing.JFrame; public class aa extends JFrame{ String image = new String("aaa.gif"); //建立一个字符串保存要用的图标的路径,关于java的路径请参考其它文档 ImageIcon test = new ImageIcon(image); //建立一个ImageIcon类,产生setIconImage()方法需要的Image数据 public aa() { super("演示自定义标题栏的图标的方法"); this.setIconImage(test.getImage()); //设置标题栏的图标为face.gif this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.show(); //this.setTitle("sdfsdf"); this.setSize(400,200); } public static void main(String[] args) { aa jIcon = new aa(); } } 方式二: package com.swing.test; import java.awt.Image; import java.awt.Toolkit; import javax.swing.JFrame; public class ImageA extends JFrame { public ImageA() { super("aa"); this.show(); this.setSize(200, 400); } public static void main(String [] args) { Toolkit kit = Toolkit.getDefaultToolkit(); Image img = kit.getImage("aaa.gif"); //JFrame frame = new JFrame(); //frame.setIconImage(img); ImageA imageA = new ImageA(); imageA.setIconImage(img); } }
效果图: