{"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":"get-system-icon","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/zh\/\u535a\u5ba2\/java\/\u83b7\u53d6\u7cfb\u7edf\u56fe\u6807","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\u53d6<\/a><\/h2>\n<p>\n<strong>Java<\/strong>\u672c\u8282\u4ecb\u7ecd\u5c06\u6307\u5b9a\u6587\u4ef6\u7684\u56fe\u6807\u63d0\u53d6\u4e3a png \u683c\u5f0f\u56fe\u50cf\u6587\u4ef6\u7684\u793a\u4f8b\u7a0b\u5e8f\u3002\u6307\u5b9a\u6587\u4ef6\u53ef\u4ee5\u662f\u6269\u5c55\u540d\u4e3a exe \u7b49\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u662f dll\u3001xls\u3001doc \u7b49\u4efb\u4f55\u6587\u4ef6\u3002<\/p>\n<p>\u6211\u5728\u4e92\u8054\u7f51\u4e0a\u641c\u7d22\u4e86\u5f88\u591a\u7c7b\u4f3c\u7684\u65b9\u6cd5\uff0c\u4f46\u90fd\u6ca1\u6709\u627e\u5230\u3002<br \/>\n\u4e0b\u9762\u5c06\u4ecb\u7ecd\u4e00\u79cd\u65b9\u6cd5\uff0c\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u975e\u5e38\u5bb9\u6613\u5730\u83b7\u53d6\u4fe1\u606f\u3002<br \/>\n\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u804a\u5929\u548c\u4fe1\u4f7f\u3001<a href=\"https:\/\/chat-messenger.com\/zh\/\u624b\u518c\/messenger_chat\/\u9644\u6ce8\/\"><strong>\u53ef\u5728\u8d34\u7eb8\u4e0a\u9644\u52a0\u6587\u4ef6\u3002<\/strong><\/a>\u7528\u4e8e\n<\/p>\n<h2 class=\"common_title\"><a name=\"1\">\u7a0b\u5e8f\u8fd0\u884c\u62bd\u67e5<\/a><\/h2>\n<p><a href=\"http:\/\/hp.vector.co.jp\/authors\/VA045104\/swing_ex\/IconExtractor.jar\"><strong>\u8fd0\u884c\u6837\u672c\u3002<\/strong><\/a><br \/>\n<br \/><span style=\"font-size:x-small;\">\u5982\u679c\u4e0e jar \u6587\u4ef6\u5173\u8054\uff0c\u5219\u53ef\u4ee5\u8fd0\u884c\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\u540e\u4f1a\u6253\u5f00\u4e3b\u7a97\u53e3\uff0c\u5c06\u60f3\u8981\u63d0\u53d6\u7684\u56fe\u6807\u76f4\u63a5\u62d6\u653e\u5230\u7a97\u53e3\u4e2d\u5373\u53ef\u3002<br \/>\n<img src=\"https:\/\/chat-messenger.com\/images\/IconExtractor.jpg\" alt=\"\u6536\u8d2d\u56fe\u6807\" border=\"0\"><\/p>\n<\/li>\n<li>png \u683c\u5f0f\u7684\u56fe\u50cf\u6587\u4ef6\u5c06\u8f93\u51fa\u5230\u4e0e\u539f\u59cb eincon \u76f8\u540c\u7684\u4f4d\u7f6e\u3002<br \/>\n<img src=\"https:\/\/chat-messenger.com\/images\/IconExtractor2.jpg\" alt=\"\u6536\u8d2d\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\">\u8ba1\u5212\u8bf4\u660e\u6837\u672c<\/a><\/h2>\n<p>\u5728 Java \u4e2d\u63d0\u53d6\u56fe\u6807\u7684\u8fc7\u7a0b\u5982\u4e0b\u3002<\/p>\n<ol>\n<li>\n\u5c06\u5916\u89c2\u8bbe\u7f6e\u4e3a Windows\u3002<br \/>\nUIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());.<\/p>\n<\/li>\n<li>\n\u62d6\u653e\u68c0\u7d22\u5230\u7684\u6587\u4ef6 <strong>javax.swing.JFileChooser.getIcon()\u3002<\/strong> \u65b9\u6cd5 <strong>javax.swing.Icon.<\/strong> \u53cd\u5bf9<\/p>\n<\/li>\n<li>\n<strong>javax.imageio.ImageIO.write()\u3002<\/strong> \u65b9\u6cd5\u5c06 Icon \u5bf9\u8c61\u8f93\u51fa\u4e3a png \u683c\u5f0f\u7684\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>\u5bfc\u5165 javax.imageio.ImageIO;<br \/>\n\u5bfc\u5165 javax.swing.ImageIcon;<br \/>\n\u5bfc\u5165 javax.swing.JFileChooser;<br \/>\n\u5bfc\u5165 javax.swing.JFrame;<br \/>\n\u5bfc\u5165 javax.swing.JLabel;<br \/>\n\u5bfc\u5165javax.swing.JPanel\uff1b<br \/>\n\u5bfc\u5165 javax.swing.SwingConstants;<br \/>\n\u5bfc\u5165 javax.swing.UIManager;<\/p>\n<p>\u516c\u5171\u7c7b IconExtractor \u6269\u5c55 JFrame<br \/>\n                \u5b9e\u73b0 DropTargetListener {<\/p>\n<p>    \u79c1\u6709 JPanel jContentPane = null;<br \/>\n    \u79c1\u6709 JLabel jLabel = null;<br \/>\n    \u79c1\u6709 JFileChooser \u9009\u62e9\u5668\uff1b<\/p>\n<p>    \u516c\u5171\u9759\u6001\u65e0\u6548\u4e3b\uff08\u5b57\u7b26\u4e32[] args\uff09{<br \/>\n        IconExtractor \u63d0\u53d6\u5668 = new IconExtractor();<br \/>\n        extractor.setVisible(true);<br \/>\n    }<\/p>\n<p>    \u516c\u5171\u56fe\u6807\u63d0\u53d6\u5668\uff08\uff09{<br \/>\n        \u6781\u597d\u7684\uff08\uff09;<br \/>\n        \u5c1d\u8bd5 {<br \/>\n            UIManager.setLookAndFeel(<br \/>\n                    UIManager.getSystemLookAndFeelClassName());<br \/>\n            \u9009\u62e9\u5668=\u65b0\u7684JFileChooser();<br \/>\n        } catch (\u5f02\u5e38 e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n        \u521d\u59cb\u5316\uff08\uff09;<br \/>\n    }<\/p>\n<p>    \u79c1\u6709\u65e0\u6548\u521d\u59cb\u5316\uff08\uff09{<br \/>\n        this.setSize(300, 200);<br \/>\n        this.setContentPane(getJContentPane());<br \/>\n        this.setTitle(\u201c\u56fe\u6807\u63d0\u53d6\u201d);<br \/>\n        this.setLocationRelativeTo(null);<br \/>\n        this.setDefaultCloseOperation(EXIT_ON_CLOSE);<br \/>\n    }<\/p>\n<p>    \u79c1\u6709 JPanel getJContentPane() {<br \/>\n        \u5982\u679c\uff08jContentPane == null\uff09{<br \/>\n            jLabel = \u65b0\u7684 JLabel();<br \/>\n            jLabel.setText(\u201c\u62d6\u52a8\u56fe\u6807\u3002\u201d);<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\uff0c\u8fd9\u4e2a\uff09\uff1b<br \/>\n            jContentPane = new JPanel();<br \/>\n            jContentPane.setLayout(new BorderLayout());<br \/>\n            jContentPane.add(jLabel, BorderLayout.CENTER);<br \/>\n        }<br \/>\n        \u8fd4\u56dejContentPane\uff1b<br \/>\n    }<\/p>\n<p>    \/\/ \u2014 \u5b9e\u73b0 DropTargetListener \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014-<br \/>\n    \u516c\u5171\u65e0\u6548\u4e0b\u964d\uff08DropTargetDropEvent dtde\uff09{<br \/>\n        dtde.acceptDrop(DnDConstants.ACTION_MOVE);<br \/>\n        \u5c1d\u8bd5 {<\/p>\n<p>            \u53ef\u8f6c\u79fb tran = dtde.getTransferable();<\/p>\n<p>            \u5217\u8868\u6587\u4ef6\u5217\u8868 = (\u5217\u8868) tran<br \/>\n                    .getTransferData(DataFlavor.javaFileListFlavor);<br \/>\n            \u8fed\u4ee3\u5668 iterator = fileList.iterator();<br \/>\n            while (iterator.hasNext()) {<br \/>\n                \u6587\u4ef6 file = (File) iterator.next();<br \/>\n                ImageIcon \u56fe\u6807 = (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                        \u65b0\u6587\u4ef6\uff08\u6269\u5c55\uff09\uff09\uff1b<br \/>\n                jLabel.setText(&ldquo;&lt;html&gt;\u63d0\u53d6\u5b8c\u6210&lt;br&gt;&rdquo; + \u5206\u673a);<br \/>\n                setIconImage(icon.getImage());<br \/>\n            }<br \/>\n            dtde.dropComplete(true);<br \/>\n        } catch (\u5f02\u5e38 e) {<br \/>\n            e.printStackTrace();<br \/>\n            dtde.dropComplete(\u5047);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \u516c\u5171\u65e0\u6548dragEnter\uff08DropTargetDragEvent e\uff09{<br \/>\n    }<\/p>\n<p>    \u516c\u5171\u65e0\u6548dragOver\uff08DropTargetDragEvent e\uff09{<br \/>\n    }<\/p>\n<p>    \u516c\u5171\u65e0\u6548dropActionChanged\uff08DropTargetDragEvent e\uff09{<br \/>\n    }<\/p>\n<p>    \u516c\u5171\u65e0\u6548dragExit\uff08DropTargetEvent e\uff09{<br \/>\n    }<br \/>\n}<br \/>\n<\/textarea><\/p>","protected":false},"excerpt":{"rendered":"<p>\u63d0\u53d6Java\u7cfb\u7edf\u56fe\u6807\u4f7f\u7528Java\u63d0\u53d6\u6307\u5b9a\u6587\u4ef6\u7684\u56fe\u6807\u4e3apng\u683c\u5f0f\u56fe\u50cf\u6587\u4ef6[...]<\/p>","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":""},"categories":[19],"tags":[],"_links":{"self":[{"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/posts\/975"}],"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}]}}