{"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_tw\/\u90e8\u843d\u683c\/java\/\u53d6\u5f97\u7cfb\u7d71\u5716\u6a19","title":{"rendered":"\u63d0\u53d6Java\u7cfb\u7d71\u5716\u6a19"},"content":{"rendered":"<h2 class=\"common_title\"><a name=\"0\">Java <strong>\u7cfb\u7d71\u5716\u793a<\/strong>\u63d0\u7149<\/a><\/h2>\n<p>\n<strong>Java<\/strong>\u9019\u88e1\u6211\u5011\u4ecb\u7d39\u4e00\u500b\u7bc4\u4f8b\u7a0b\u5e8f\uff0c\u5c07\u6307\u5b9a\u6a94\u6848\u7684\u5716\u793a\u63d0\u53d6\u70bapng\u683c\u5f0f\u7684\u5716\u50cf\u6a94\u6848\u3002\u6307\u5b9a\u7684\u6a94\u6848\u53ef\u4ee5\u662f\u4efb\u4f55\u526f\u6a94\u540d\u70ba.exe\u7684\u53ef\u57f7\u884c\u6a94\u3001dll\u3001xls\u3001doc\u7b49\u3002<\/p>\n<p>\u6211\u5728\u4e92\u806f\u7db2\u4e0a\u5c0b\u627e\u985e\u4f3c\u7684\u65b9\u6cd5\uff0c\u4f46\u627e\u4e0d\u5230\u4efb\u4f55\u6771\u897f\u3002<br \/>\n\u4e0d\u904e\uff0c\u6211\u767c\u73fe\u4e86\u4e00\u500b\u975e\u5e38\u5bb9\u6613\u7372\u5f97\u7684\u65b9\u6cd5\uff0c\u6240\u4ee5\u6211\u5c07\u5b83\u4ecb\u7d39\u7d66\u4f60\u3002<br \/>\n\u53e6\u5916\uff0c\u5728Chat&amp;Messenger\u4e2d\uff0c\u9019\u500b\u65b9\u6cd5\u662f<a href=\"https:\/\/chat-messenger.com\/zh_tw\/\u624b\u52d5\u7684\/messenger_chat\/\u9ecf\u6eef\u4fbf\u7b8b\/\"><strong>\u80fd\u5920\u5c07\u6587\u4ef6\u9644\u52a0\u5230\u4fbf\u7c64\u4e0a<\/strong><\/a>\u5b83\u7528\u65bc\n<\/p>\n<h2 class=\"common_title\"><a name=\"1\">\u7bc4\u4f8b\u7a0b\u5f0f\u904b\u884c\u78ba\u8a8d<\/a><\/h2>\n<p><a href=\"http:\/\/hp.vector.co.jp\/authors\/VA045104\/swing_ex\/IconExtractor.jar\"><strong>\u904b\u884c\u6a23\u672c<\/strong><\/a><br \/>\n<br \/><span style=\"font-size:x-small;\">*\u5982\u679c\u95dc\u806f\u4e86jar\u6a94\u5c31\u53ef\u4ee5\u57f7\u884c\u3002<\/span><\/p>\n<ol>\n<li>\u53d6\u5f97\u7bc4\u4f8b\u539f\u59cb\u78bc\uff0c\u7de8\u8b6f\u4e26\u904b\u884c\u5b83\u3002\n<\/li>\n<li>\u7576\u60a8\u555f\u52d5\u5b83\u6642\uff0c\u4e3b\u8996\u7a97\u5c07\u6253\u958b\uff0c\u56e0\u6b64\u53ea\u9700\u5c07\u8981\u63d0\u53d6\u7684\u5716\u793a\u62d6\u653e\u5230\u8996\u7a97\u4e2d\u5373\u53ef\u3002<br \/>\n<img src=\"https:\/\/chat-messenger.com\/images\/IconExtractor.jpg\" alt=\"\u53d6\u5f97\u5716\u793a\" border=\"0\"><\/p>\n<\/li>\n<li>png \u683c\u5f0f\u7684\u5f71\u50cf\u6a94\u6848\u5c07\u8f38\u51fa\u5230\u8207\u539f\u59cb\u5716\u793a\u76f8\u540c\u7684\u4f4d\u7f6e\u3002<br \/>\n<img src=\"https:\/\/chat-messenger.com\/images\/IconExtractor2.jpg\" alt=\"\u53d6\u5f97\u5716\u793a\" 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\">\u7bc4\u4f8b\u7a0b\u5f0f\u8aaa\u660e<\/a><\/h2>\n<p>Java\u4e2d\u63d0\u53d6\u5716\u6a19\u7684\u904e\u7a0b\u662f\u900f\u904e\u4ee5\u4e0b\u65b9\u6cd5\u5be6\u73fe\u7684\u3002<\/p>\n<ol>\n<li>\n\u5c07\u5916\u89c0\u8a2d\u5b9a\u70ba Windows\u3002<br \/>\nUIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());<\/p>\n<\/li>\n<li>\n\u62d6\u653e\u7372\u5f97\u7684\u6587\u4ef6 <strong>javax.swing.JFileChooser.getIcon()<\/strong> \u7528\u65b9\u6cd5 <strong>javax.swing.Icon<\/strong> \u8f49\u63db\u70ba\u7269\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<strong>javax.imageio.ImageIO.write()<\/strong> \u4f7f\u7528\u6b64\u65b9\u6cd5\u5c07 Icon \u7269\u4ef6\u8f38\u51fa\u70ba png \u683c\u5f0f\u7684\u5f71\u50cf\u6a94\u6848\u3002<\/p>\n<\/li>\n<\/ol>\n<h2 class=\"common_title\"><a name=\"3\">\u7bc4\u4f8b\u7a0b\u5f0f<\/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>\u5c0e\u5165 javax.imageio.ImageIO;<br \/>\n\u5c0e\u5165 javax.swing.ImageIcon;<br \/>\n\u5c0e\u5165 javax.swing.JFileChooser;<br \/>\n\u5c0e\u5165 javax.swing.JFrame;<br \/>\n\u5c0e\u5165 javax.swing.JLabel;<br \/>\n\u5c0e\u5165javax.swing.JPanel\uff1b<br \/>\n\u5c0e\u5165 javax.swing.SwingConstants;<br \/>\n\u5c0e\u5165 javax.swing.UIManager;<\/p>\n<p>\u516c\u5171\u985e\u5225 IconExtractor \u64f4\u5145 JFrame<br \/>\n                \u5be6\u4f5c DropTargetListener {<\/p>\n<p>    \u79c1\u6709 JPanel jContentPane = null;<br \/>\n    \u79c1\u6709 JLabel jLabel = null;<br \/>\n    \u79c1\u6709 JFileChooser \u9078\u64c7\u5668\uff1b<\/p>\n<p>    \u516c\u5171\u975c\u614b\u7121\u6548\u4e3b\uff08\u5b57\u4e32[] args\uff09{<br \/>\n        IconExtractor \u63d0\u53d6\u5668 = new IconExtractor();<br \/>\n        extractor.setVisible(true);<br \/>\n    }<\/p>\n<p>    \u516c\u5171\u5716\u6a19\u63d0\u53d6\u5668\uff08\uff09{<br \/>\n        \u6975\u597d\u7684\uff08\uff09;<br \/>\n        \u5617\u8a66 {<br \/>\n            UIManager.setLookAndFeel(<br \/>\n                    UIManager.getSystemLookAndFeelClassName());<br \/>\n            \u9078\u64c7\u5668=\u65b0\u7684JFileChooser();<br \/>\n        } catch (\u7570\u5e38 e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n        \u521d\u59cb\u5316\uff08\uff09;<br \/>\n    }<\/p>\n<p>    \u79c1\u6709\u7121\u6548\u521d\u59cb\u5316\uff08\uff09{<br \/>\n        this.setSize(300, 200);<br \/>\n        this.setContentPane(getJContentPane());<br \/>\n        this.setTitle(\u201c\u5716\u6a19\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\u66f3\u5716\u793a\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\u9019\u500b\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 \u5be6\u4f5c DropTargetListener \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014-<br \/>\n    \u516c\u5171\u7121\u6548\u4e0b\u964d\uff08DropTargetDropEvent dtde\uff09{<br \/>\n        dtde.acceptDrop(DnDConstants.ACTION_MOVE);<br \/>\n        \u5617\u8a66 {<\/p>\n<p>            \u53ef\u8f49\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                \u6a94\u6848 file = (File) iterator.next();<br \/>\n                ImageIcon \u5716\u793a = (ImageIcon) Chooser.getIcon(file);<br \/>\n                String ext = file.getAbsoluteFile() + \u201c.png\u201d;<br \/>\n                \/\/ \u5132\u5b58\u5716\u7247\u6587\u4ef6<br \/>\n                ImageIO.write((BufferedImage) icon.getImage(), \u201cpng\u201d,<br \/>\n                        \u65b0\u6587\u4ef6\uff08\u64f4\u5c55\uff09\uff09\uff1b<br \/>\n                jLabel.setText(&ldquo;&lt;html&gt;\u63d0\u53d6\u5b8c\u6210&lt;br&gt;&rdquo; + \u5206\u6a5f);<br \/>\n                setIconImage(icon.getImage());<br \/>\n            }<br \/>\n            dtde.dropComplete(true);<br \/>\n        } catch (\u7570\u5e38 e) {<br \/>\n            e.printStackTrace();<br \/>\n            dtde.dropComplete(\u5047);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \u516c\u5171\u7121\u6548dragEnter\uff08DropTargetDragEvent e\uff09{<br \/>\n    }<\/p>\n<p>    \u516c\u5171\u7121\u6548dragOver\uff08DropTargetDragEvent e\uff09{<br \/>\n    }<\/p>\n<p>    \u516c\u5171\u7121\u6548dropActionChanged\uff08DropTargetDragEvent e\uff09{<br \/>\n    }<\/p>\n<p>    \u516c\u5171\u7121\u6548dragExit\uff08DropTargetEvent e\uff09{<br \/>\n    }<br \/>\n}<br \/>\n<\/textarea><\/p>","protected":false},"excerpt":{"rendered":"<p>\u63d0\u53d6Java\u7cfb\u7d71\u5716\u793a\u4f7f\u7528Java\u63d0\u53d6\u6307\u5b9a\u6a94\u6848\u7684\u5716\u793a\u70bapng\u683c\u5f0f\u5716\u50cf\u6a94\u6848[...]<\/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_tw\/wp-json\/wp\/v2\/posts\/975"}],"collection":[{"href":"https:\/\/chat-messenger.com\/zh_tw\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chat-messenger.com\/zh_tw\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/zh_tw\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/zh_tw\/wp-json\/wp\/v2\/comments?post=975"}],"version-history":[{"count":5,"href":"https:\/\/chat-messenger.com\/zh_tw\/wp-json\/wp\/v2\/posts\/975\/revisions"}],"predecessor-version":[{"id":1872,"href":"https:\/\/chat-messenger.com\/zh_tw\/wp-json\/wp\/v2\/posts\/975\/revisions\/1872"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/zh_tw\/wp-json\/wp\/v2\/media?parent=975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/zh_tw\/wp-json\/wp\/v2\/categories?post=975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/zh_tw\/wp-json\/wp\/v2\/tags?post=975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}