in java.awt.Frame class:setIconImage public void setIconImage(Image image) Sets the image to be displayed in the minimized icon for this frame. Not all platforms support the concept of minimizing a window. Parameters: image - the icon image to be displayed. If this parameter is null then the icon image is set to the default image, which may vary with platform.see also: jdk API help document.
Image image = kit.getImage("icon.gif");//指定图标文件的相对路径
setIconImage(image);//调用setIconImage方法,这是定义在JFrame的父类Frame类中的方法。
public void setIconImage(Image image)
Sets the image to be displayed in the minimized icon for this frame. Not all platforms support the concept of minimizing a window. Parameters:
image - the icon image to be displayed. If this parameter is null then the icon image is set to the default image, which may vary with platform.see also: jdk API help document.
JFrame frame=new JFrame("图片事例");
frame.setIconImage(image);
import java.awt.*;
import javax.swing.ImageIcon;public class imageIcon
{
public static void main(String args[])
{
ImageIcon icon=new ImageIcon("icon.jpg");
Frame f=new Frame("我的第一个窗口程序");
f.setBounds(0,0,100,200);
f.setIconImage(icon.getImage());
f.show();
}
}
这哪里是什么秘密
Image img=kit.getImage("tomcat.gif");
setIconImage(img);
试试,应该行
确认一下是否图片路径错误
[email protected]
{
public static void main(String args[])
{
ImageIcon icon=new ImageIcon();
icon.setImage("1.jpg");
JFrame f=new JFrame("我的第一个窗口程序");
f.setBounds(0,0,100,200);
f.setIconImage(icon);//icon.getImage());
f.show();
}
}
好用!这个!
javax.swing.ImageIcon icon = new javax.swing.ImageIcon(getClass().getResource("图像资源路径"));
javax.swing.JFrame window = new JFrame("Test Window");
window.setBounds(100,100,200,200);
window.setIconImage(icon.getImage());
window.setVisiable(true);
就可以了
要把资源读入才可以显示