java可使用FileSystemView和ShellFolder類獲取文件的小圖標(biāo)和大圖標(biāo),以下是詳細(xì)代碼:
目前成都創(chuàng)新互聯(lián)已為成百上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、網(wǎng)站運(yùn)營、企業(yè)網(wǎng)站設(shè)計(jì)、大柴旦網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
import?java.awt.FlowLayout;
import?java.io.File;
import?java.io.FileNotFoundException;
import?javax.swing.Icon;
import?javax.swing.ImageIcon;
import?javax.swing.JFrame;
import?javax.swing.JLabel;
import?javax.swing.filechooser.FileSystemView;
public?class?GetFileIcon?{
/**
*?@param?args
*/
public?static?void?main(?String[]?args?)
{
String????filePath????=?"D:/sheet1.xlsx";
File????f????????=?new?File(?filePath?);
JFrame????frm????????=?new?JFrame();
frm.setSize(?300,?200?);
frm.setLocationRelativeTo(?null?);
frm.setDefaultCloseOperation(?JFrame.EXIT_ON_CLOSE?);
frm.setVisible(?true?);
frm.setLayout(?new?FlowLayout(?10,?10,?FlowLayout.LEADING?)?);
JLabel?sl?=?new?JLabel(?"小圖標(biāo)"?);
frm.add(?sl?);
JLabel?bl?=?new?JLabel(?"大圖標(biāo)"?);
frm.add(?bl?);
sl.setIcon(?getSmallIcon(?f?)?);
bl.setIcon(?getBigIcon(?f?)?);
}
/**
*?獲取小圖標(biāo)
*?@param?f
*?@return
*/
private?static?Icon?getSmallIcon(?File?f?)
{
if?(?f?!=?null??f.exists()?)
{
FileSystemView?fsv?=?FileSystemView.getFileSystemView();
return(fsv.getSystemIcon(?f?)?);
}
return(null);
}
/**
*?獲取大圖標(biāo)
*?@param?f
*?@return
*/
private?static?Icon?getBigIcon(?File?f?)
{
if?(?f?!=?null??f.exists()?)
{
try?{
sun.awt.shell.ShellFolder?sf?=?sun.awt.shell.ShellFolder.getShellFolder(?f?);
return(new?ImageIcon(?sf.getIcon(?true?)?)?);
}?catch?(?FileNotFoundException?e?)?{
/*?TODO?Auto-generated?catch?block?*/
e.printStackTrace();
}
}
return(null);
}
}
首先,打開java開發(fā)工具,MyEclipse工具,添加一個(gè)java項(xiàng)目,在這里小編不做圖片介紹了
2
/7
進(jìn)入到Java Project中,引入相關(guān)的jar包和import相關(guān)的java類,編寫一個(gè)java awt窗口的java代碼,保存代碼(要有這個(gè)良好的習(xí)慣哦)最重要的內(nèi)容來了,要修改java運(yùn)行界面左上角的logo圖標(biāo)
你需要在java代碼中加入如下兩個(gè)語句
Image icon = Toolkit.getDefaultToolkit().getImage("G:\\0000分享\\分享\\圖片1.jpg"); // 圖片的具體位置
jf.setIconImage(icon); //設(shè)置窗口的logo保存好新修改的java代碼后,再次點(diǎn)擊運(yùn)行java項(xiàng)目,你將會(huì)看到如下的效果,java運(yùn)行界面左上角的logo圖標(biāo)真的就改變了,下面將附上我使用的圖片及運(yùn)行畫面效果
1.
網(wǎng)站圖標(biāo)是在html或者jsp頁面中設(shè)置的
2.
在網(wǎng)頁的
head.../head
區(qū)加入代碼:link
rel="Shortcut
Icon"
href="favicon.ico"
/,如果用這一種方法的話,其中
ICO
文件的文件名就不一定要用
favicon.ico了,可以用任意的名字來命名,如:aoul.ico,你甚至可以使每一個(gè)目錄下的每一個(gè)網(wǎng)頁文件的IE地址欄圖標(biāo)都不同,但前提是
必須做到圖標(biāo)文件的鏈接地址要正確。
3
.動(dòng)態(tài)ico圖標(biāo)的實(shí)現(xiàn)方法,先把做好的gif動(dòng)態(tài)圖標(biāo)命名為favico.gif
head/head之間加上:
link
rel="icon"
href="favicon.gif"
type="image/gif"
import?java.awt.*;
import?java.awt.event.*;
import?javax.swing.*;
public?class?Practise{
public?static?void?main(String[]?args)?{
new?MyFrame();
}
}
class?MyFrame?extends?JFrame
{
public?MyFrame()
{
final?JButton?btnChangeImage=new?JButton("改變圖標(biāo)");
btnChangeImage.setIcon(new?ImageIcon(".\\images\\icon1.png"));
btnChangeImage.addActionListener(new?ActionListener(){
@Override
public?void?actionPerformed(ActionEvent?arg0)?{
btnChangeImage.setIcon(new?ImageIcon(".\\images\\icon2.png"));
}
});
this.getContentPane().add(btnChangeImage);
this.setSize(300,200);
this.setLayout(new?FlowLayout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//用戶單擊“關(guān)閉”按鈕時(shí)關(guān)閉窗口
this.setVisible(true);
}
}
分享名稱:java圖標(biāo)代碼 java編程軟件圖標(biāo)
當(dāng)前地址:http://chinadenli.net/article38/doeigpp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、定制網(wǎng)站、Google、、網(wǎng)站設(shè)計(jì)公司、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)