{"id":975,"date":"2018-04-17T18:59:08","date_gmt":"2018-04-17T09:59:08","guid":{"rendered":"https:\/\/chat-messenger.com\/?p=975"},"modified":"2018-12-23T01:59:03","modified_gmt":"2018-12-22T16:59:03","slug":"%e8%8e%b7%e5%8f%96%e7%b3%bb%e7%bb%9f%e5%9b%be%e6%a0%87","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/zh\/blog\/java\/get-system-icon","title":{"rendered":"\u63d0\u53d6 Java \u7cfb\u7edf\u56fe\u6807"},"content":{"rendered":"<h2 class=\"common_title\"><a name=\"0\">Java <strong>\u7cfb\u7edf\u56fe\u6807<\/strong>\u63d0\u70bc<\/a><\/h2>\n<p>\n<strong>Java<\/strong>\u8fd9\u662f\u4e00\u4e2a\u793a\u4f8b\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u5c06\u6307\u5b9a\u6587\u4ef6\u4e2d\u7684\u56fe\u6807\u63d0\u53d6\u5230 PNG \u56fe\u50cf\u6587\u4ef6\u4e2d\u3002\u6307\u5b9a\u6587\u4ef6\u53ef\u4ee5\u662f\u4efb\u4f55\u6587\u4ef6\u7c7b\u578b\uff0c\u5305\u62ec\u6269\u5c55\u540d\u4e3a .exe \u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4ee5\u53ca .dll\u3001.xls\u3001.doc \u7b49\u6587\u4ef6\u3002<\/p>\n<p>\u6211\u5728\u7f51\u4e0a\u641c\u7d22\u8fc7\u7c7b\u4f3c\u7684\u65b9\u6cd5\uff0c\u4f46\u6ca1\u6709\u627e\u5230\u3002<br \/>\n\u4e0d\u8fc7\uff0c\u6211\u53d1\u73b0\u4e86\u4e00\u79cd\u975e\u5e38\u7b80\u5355\u7684\u83b7\u53d6\u65b9\u6cd5\uff0c\u6240\u4ee5\u6211\u4f1a\u548c\u4f60\u4eec\u5206\u4eab\u3002<br \/>\n\u8bf7\u6ce8\u610f\uff0cChat&amp;Messenger \u4e0d\u4f7f\u7528\u6b64\u65b9\u6cd5\u3002<a href=\"\/zh\/%e6%89%8b%e5%86%8c\/%e8%81%8a%e5%a4%a9-2\/%e9%99%84%e6%b3%a8\/\"><strong>\u4e00\u9879\u5c06\u6587\u4ef6\u9644\u52a0\u5230\u4fbf\u7b7e\u7684\u529f\u80fd\u3002<\/strong><\/a>\u6211\u6b63\u5728\u4f7f\u7528\u5b83\u3002\n<\/p>\n<h2 class=\"common_title\"><a name=\"1\">\u793a\u4f8b\u7a0b\u5e8f\u8fd0\u884c\u9a8c\u8bc1<\/a><\/h2>\n<p><a href=\"http:\/\/hp.vector.co.jp\/authors\/VA045104\/swing_ex\/IconExtractor.jar\"><strong>\u8fd0\u884c\u793a\u4f8b<\/strong><\/a><br \/>\n<br \/><span style=\"font-size:x-small;\">*\u5982\u679c\u4e0e jar \u6587\u4ef6\u5173\u8054\uff0c\u5219\u53ef\u4ee5\u6267\u884c\u6b64\u64cd\u4f5c\u3002<\/span><\/p>\n<ol>\n<li>\u83b7\u53d6\u793a\u4f8b\u6e90\u4ee3\u7801\uff0c\u7f16\u8bd1\u5e76\u8fd0\u884c\u5b83\u3002\n<\/li>\n<li>\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\u540e\uff0c\u4e3b\u7a97\u53e3\u5c06\u4f1a\u6253\u5f00\u3002\u53ea\u9700\u5c06\u8981\u63d0\u53d6\u7684\u56fe\u6807\u62d6\u653e\u5230\u6b64\u7a97\u53e3\u4e2d\u5373\u53ef\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/chat-messenger.com\/images\/IconExtractor.jpg\" alt=\"\u83b7\u53d6\u56fe\u6807\" border=\"0\"><\/p>\n<\/li>\n<li>PNG \u56fe\u50cf\u6587\u4ef6\u5c06\u8f93\u51fa\u5230\u4e0e\u539f\u59cb\u56fe\u6807\u76f8\u540c\u7684\u4f4d\u7f6e\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/chat-messenger.com\/images\/IconExtractor2.jpg\" alt=\"\u83b7\u53d6\u56fe\u6807\" border=\"0\"><\/p>\n<\/li>\n<\/ol>\n<p><script type=\"text\/javascript\" src=\"https:\/\/chat-messenger.com\/js\/common.js?dd12sssas2223\" charset=\"UTF-8\"><\/script><br \/>\n<script type=\"text\/javascript\"> writePR(); <\/script><\/p>\n<h2 class=\"common_title\"><a name=\"2\">\u793a\u4f8b\u7a0b\u5e8f\u8bf4\u660e<\/a><\/h2>\n<p>Java \u4e2d\u56fe\u6807\u63d0\u53d6\u8fc7\u7a0b\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\u5b9e\u73b0\u3002<\/p>\n<ol>\n<li>\n\u5c06\u5916\u89c2\u8bbe\u7f6e\u4e3a Windows \u6837\u5f0f\u3002<br \/>\nUIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());<\/p>\n<\/li>\n<li>\n\u901a\u8fc7\u62d6\u653e\u83b7\u53d6\u7684\u6587\u4ef6 <strong>javax.swing.JFileChooser.getIcon()<\/strong> \u65b9\u6cd5 <strong>javax.swing.Icon<\/strong> \u5c06\u5176\u8f6c\u6362\u4e3a\u5bf9\u8c61\u3002<\/p>\n<\/li>\n<li>\n<strong>javax.imageio.ImageIO.write()<\/strong> \u6b64\u65b9\u6cd5\u5c06 Icon \u5bf9\u8c61\u8f93\u51fa\u4e3a PNG \u56fe\u50cf\u6587\u4ef6\u3002<\/p>\n<\/li>\n<\/ol>\n<h2 class=\"common_title\"><a name=\"3\">\u793a\u4f8b\u7a0b\u5e8f<\/a><\/h2>\n<p><textarea readonly=\"readonly\" style=\"font-size: 13px;height: 400px;\" class=\"src\" onclick=\"this.focus();this.select()\">import java.awt.BorderLayout;<br \/>\nimport java.awt.Color;<br \/>\nimport java.awt.datatransfer.DataFlavor;<br \/>\nimport java.awt.datatransfer.Transferable;<br \/>\nimport java.awt.dnd.DnDConstants;<br \/>\nimport java.awt.dnd.DropTarget;<br \/>\nimport java.awt.dnd.DropTargetDragEvent;<br \/>\nimport java.awt.dnd.DropTargetDropEvent;<br \/>\nimport java.awt.dnd.DropTargetEvent;<br \/>\nimport java.awt.dnd.DropTargetListener;<br \/>\nimport java.awt.image.BufferedImage;<br \/>\nimport java.io.File;<br \/>\nimport java.util.Iterator;<br \/>\nimport java.util.List;<\/p>\n<p>import javax.imageio.ImageIO;<br \/>\nimport javax.swing.ImageIcon;<br \/>\nimport javax.swing.JFileChooser;<br \/>\nimport javax.swing.JFrame;<br \/>\nimport javax.swing.JLabel;<br \/>\nimport javax.swing.JPanel;<br \/>\nimport javax.swing.SwingConstants;<br \/>\nimport javax.swing.UIManager;<\/p>\n<p>public class IconExtractor extends JFrame<br \/>\n                implements DropTargetListener {<\/p>\n<p>    private JPanel jContentPane = null;<br \/>\n    private JLabel jLabel = null;<br \/>\n    private JFileChooser \u9009\u62e9\u5668;<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        IconExtractor extractor = new IconExtractor();<br \/>\n        extractor.setVisible(true);<br \/>\n    }<\/p>\n<p>    public IconExtractor() {<br \/>\n        \u6781\u597d\u7684\uff08\uff09;<br \/>\n        \u5c1d\u8bd5 {<br \/>\n            UIManager.setLookAndFeel(<br \/>\n                    UIManager.getSystemLookAndFeelClassName());<br \/>\n            chooser = new JFileChooser();<br \/>\n        } catch (Exception e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n        \u521d\u59cb\u5316\uff08\uff09;<br \/>\n    }<\/p>\n<p>    private void initialize() {<br \/>\n        this.setSize(300, 200);<br \/>\n        this.setContentPane(getJContentPane());<br \/>\n        this.setTitle(&quot;\u56fe\u6807\u63d0\u53d6&quot;);<br \/>\n        this.setLocationRelativeTo(null);<br \/>\n        this.setDefaultCloseOperation(EXIT_ON_CLOSE);<br \/>\n    }<\/p>\n<p>    private JPanel getJContentPane() {<br \/>\n        \u5982\u679c (jContentPane == null) {<br \/>\n            jLabel = new JLabel();<br \/>\n            jLabel.setText(&quot;\u8bf7\u62d6\u52a8\u56fe\u6807\u3002&quot;);<br \/>\n            jLabel.setBackground(Color.white);<br \/>\n            jLabel.setHorizontalAlignment(SwingConstants.CENTER);<br \/>\n            jLabel.setOpaque(true);<br \/>\n            \u65b0\u7684 DropTarget(jLabel,<br \/>\n                    DnDConstants.ACTION_COPY_OR_MOVE\uff0cthis);<br \/>\n            jContentPane = new JPanel();<br \/>\n            jContentPane.setLayout(new BorderLayout());<br \/>\n            jContentPane.add(jLabel, BorderLayout.CENTER);<br \/>\n        }<br \/>\n        \u8fd4\u56de jContentPane\uff1b;<br \/>\n    }<\/p>\n<p>    \/\/ \u2014 \u5b9e\u73b0 DropTargetListener \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014-<br \/>\n    public void drop(DropTargetDropEvent dtde) {<br \/>\n        dtde.acceptDrop(DnDConstants.ACTION_MOVE);<br \/>\n        \u5c1d\u8bd5 {<\/p>\n<p>            \u53ef\u8f6c\u79fb\u7684 tran = dtde.getTransferable();<\/p>\n<p>            \u5217\u8868 fileList = (\u5217\u8868) tran<br \/>\n                    .getTransferData(DataFlavor.javaFileListFlavor);<br \/>\n            Iterator iterator = fileList.iterator();<br \/>\n            while (iterator.hasNext()) {<br \/>\n                \u6587\u4ef6 file = (File) iterator.next();<br \/>\n                ImageIcon icon = (ImageIcon) chooser.getIcon(file);<br \/>\n                String ext = file.getAbsoluteFile() + \u201c.png\u201d;<br \/>\n                \/\/ \u4fdd\u5b58\u56fe\u50cf\u6587\u4ef6<br \/>\n                ImageIO.write((BufferedImage) icon.getImage(), \u201cpng\u201d,<br \/>\n                        new File(ext));<br \/>\n                jLabel.setText(&ldquo;&lt;html&gt;\u63d0\u53d6\u5b8c\u6210&lt;br&gt;&rdquo;&amp;quot; + ext);<br \/>\n                \u8bbe\u7f6e\u56fe\u6807\u56fe\u50cf(icon.getImage());<br \/>\n            }<br \/>\n            dtde.dropComplete(true);<br \/>\n        } catch (Exception e) {<br \/>\n            e.printStackTrace();<br \/>\n            dtde.dropComplete(false);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public void dragEnter(DropTargetDragEvent e) {<br \/>\n    }<\/p>\n<p>    public void dragOver(DropTargetDragEvent e) {<br \/>\n    }<\/p>\n<p>    public void dropActionChanged(DropTargetDragEvent e) {<br \/>\n    }<\/p>\n<p>    public void dragExit(DropTargetEvent e) {<br \/>\n    }<br \/>\n}<br \/>\n<\/textarea><\/p>","protected":false},"excerpt":{"rendered":"<p>Java \u30b7\u30b9\u30c6\u30e0\u30a2\u30a4\u30b3\u30f3\u3092\u62bd\u51fa Java\u3067\u3001\u6307\u5b9a\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb\u306e\u30a2\u30a4\u30b3\u30f3\u3092 png \u5f62\u5f0f\u306e\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u3078\u62bd\u51fa [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[19],"tags":[],"class_list":["post-975","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/posts\/975","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/comments?post=975"}],"version-history":[{"count":5,"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/posts\/975\/revisions"}],"predecessor-version":[{"id":1872,"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/posts\/975\/revisions\/1872"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/media?parent=975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/categories?post=975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/tags?post=975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}