国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

java根據擴展名獲取系統圖標和文件圖標示例

2019-11-26 15:37:28
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

import java.io.File;
import java.io.IOException;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.BoxLayout;
import javax.swing.filechooser.FileSystemView;
import sun.awt.shell.ShellFolder;

public class FileIconExtractor extends JFrame implements ActionListener{
private JButton getIconBtn = new JButton("get Icon");
private JPanel iconPanel = new JPanel();
private JTextField extField = new JTextField();
private JLabel smallIconLabel = new JLabel("small Icon here");
private JLabel bigIconLabel = new JLabel("big Icon here");

public FileIconExtractor() {
this.setSize(200, 150);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new BorderLayout());
getIconBtn.setActionCommand("GETICON");
getIconBtn.addActionListener(this);
iconPanel.setLayout(new BoxLayout(iconPanel, BoxLayout.Y_AXIS));
iconPanel.add(smallIconLabel);
iconPanel.add(bigIconLabel);
this.add(extField, BorderLayout.NORTH);
this.add(iconPanel, BorderLayout.CENTER);
this.add(getIconBtn, BorderLayout.SOUTH);
this.setVisible(true);
}

public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("GETICON")) {
String ext = extField.getText();
File file;
try
{
      file = File.createTempFile("icon", "." + ext);
      FileSystemView view = FileSystemView.getFileSystemView();
      Icon smallIcon = view.getSystemIcon(file);
      ShellFolder shellFolder = ShellFolder.getShellFolder(file);
      Icon bigIcon = new ImageIcon(shellFolder.getIcon(true));
      setIconLabel(smallIcon, bigIcon);
      file.delete();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}

private void setIconLabel(Icon smallIcon, Icon bigIcon) {
smallIconLabel.setIcon(smallIcon);
bigIconLabel.setIcon(bigIcon);
}

public static void main(String[] args) {
FileIconExtractor fie = new FileIconExtractor();
}
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 驻马店市| 阳春市| 永仁县| 米泉市| 九龙县| 鄂伦春自治旗| 富源县| 四平市| 宝山区| 金阳县| 阳朔县| 东安县| 乐东| 且末县| 修武县| 丰城市| 青海省| 山丹县| 当雄县| 顺义区| 彭泽县| 沅陵县| 杭州市| 宾阳县| 郧西县| 时尚| 孟津县| 常宁市| 怀集县| 崇阳县| 峡江县| 宿松县| 启东市| 叙永县| 高青县| 香港| 常德市| 陕西省| 南城县| 宁化县| 泰和县|