一曲肠断,天涯何处觅知音!

你把爱藏在眼底,我把爱锁进心头. 当思念,在梦中也流不出眼泪, 当邂逅,只有匆匆一闪却没有一点点理由, 正是我想你心痛的时候!
posts - 1, comments - 0, trackbacks - 0, articles - 0

2008年10月21日

为java的窗口实例设置小图标,最好是PNG格式的

 


 

import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;


public class Frame extends JFrame {
 
          public static void main(String[] args) {
                    new Frame().launchFrame();
          }
 
          public void launchFrame() {
                      setSize(300,300);
                      setTitle("窗口示例");

                      //获取图片并设为窗口图标,注意,这里的images文件夹必须和Frame.java文件在同一个包中

                       java.net.URL imgURL = Frame.class.getResource("/images/yourImage.png");
                       ImageIcon imgIcon = new ImageIcon(imgURL);
                       Image img = imgIcon.getImage();
                       this.setIconImage(img
);

                      //将窗口显示在屏幕正中
                      this.setLocationRelativeTo(null);
                      setVisible(true);
           }

}

posted @ 2008-10-21 20:13 feiqitian 阅读(1495) | 评论 (0)编辑 收藏