{"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\/vi\/blog\/java\/lay-bieu-tuong-he-thong","title":{"rendered":"Tr\u00edch xu\u1ea5t bi\u1ec3u t\u01b0\u1ee3ng h\u1ec7 th\u1ed1ng Java"},"content":{"rendered":"<h2 class=\"common_title\"><a name=\"0\">Java <strong>bi\u1ec3u t\u01b0\u1ee3ng h\u1ec7 th\u1ed1ng<\/strong>tr\u00edch xu\u1ea5t<\/a><\/h2>\n<p>\n<strong>Java<\/strong>\u1ede \u0111\u00e2y ch\u00fang t\u00f4i gi\u1edbi thi\u1ec7u m\u1ed9t ch\u01b0\u01a1ng tr\u00ecnh m\u1eabu tr\u00edch xu\u1ea5t bi\u1ec3u t\u01b0\u1ee3ng c\u1ee7a m\u1ed9t t\u1ec7p \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh th\u00e0nh t\u1ec7p h\u00ecnh \u1ea3nh c\u00f3 \u0111\u1ecbnh d\u1ea1ng png. T\u1ec7p \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh c\u00f3 th\u1ec3 l\u00e0 b\u1ea5t k\u1ef3 t\u1ec7p th\u1ef1c thi n\u00e0o c\u00f3 ph\u1ea7n m\u1edf r\u1ed9ng .exe, dll, xls, doc, v.v.<\/p>\n<p>T\u00f4i \u0111\u00e3 t\u00ecm ki\u1ebfm c\u00e1c ph\u01b0\u01a1ng ph\u00e1p t\u01b0\u01a1ng t\u1ef1 tr\u00ean internet nh\u01b0ng kh\u00f4ng t\u00ecm th\u1ea5y g\u00ec.<br \/>\nTuy nhi\u00ean, t\u00f4i \u0111\u00e3 ph\u00e1t hi\u1ec7n ra m\u1ed9t ph\u01b0\u01a1ng ph\u00e1p th\u1ef1c s\u1ef1 d\u1ec5 th\u1ef1c hi\u1ec7n n\u00ean t\u00f4i s\u1ebd gi\u1edbi thi\u1ec7u cho b\u1ea1n.<br \/>\nNgo\u00e0i ra, trong Chat&amp;Messenger, ph\u01b0\u01a1ng ph\u00e1p n\u00e0y c\u00f2n<a href=\"https:\/\/chat-messenger.com\/vi\/thu-cong\/messenger_chat\/dinh_note\/\"><strong>Kh\u1ea3 n\u0103ng \u0111\u00ednh k\u00e8m t\u1eadp tin v\u00e0o ghi ch\u00fa d\u00e1n<\/strong><\/a>N\u00f3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng trong\n<\/p>\n<h2 class=\"common_title\"><a name=\"1\">X\u00e1c nh\u1eadn v\u1eadn h\u00e0nh ch\u01b0\u01a1ng tr\u00ecnh m\u1eabu<\/a><\/h2>\n<p><a href=\"http:\/\/hp.vector.co.jp\/authors\/VA045104\/swing_ex\/IconExtractor.jar\"><strong>ch\u1ea1y m\u1eabu<\/strong><\/a><br \/>\n<br \/><span style=\"font-size:x-small;\">*N\u1ebfu t\u1ec7p jar \u0111\u01b0\u1ee3c li\u00ean k\u1ebft, n\u00f3 c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c th\u1ef1c thi.<\/span><\/p>\n<ol>\n<li>L\u1ea5y ngu\u1ed3n m\u1eabu, bi\u00ean d\u1ecbch v\u00e0 ch\u1ea1y n\u00f3.\n<\/li>\n<li>Khi kh\u1edfi \u0111\u1ed9ng l\u00ean, c\u1eeda s\u1ed5 ch\u00ednh s\u1ebd m\u1edf ra n\u00ean b\u1ea1n ch\u1ec9 c\u1ea7n k\u00e9o th\u1ea3 bi\u1ec3u t\u01b0\u1ee3ng mu\u1ed1n gi\u1ea3i n\u00e9n v\u00e0o c\u1eeda s\u1ed5.<br \/>\n<img src=\"https:\/\/chat-messenger.com\/images\/IconExtractor.jpg\" alt=\"Nh\u1eadn bi\u1ec3u t\u01b0\u1ee3ng\" border=\"0\"><\/p>\n<\/li>\n<li>T\u1ec7p h\u00ecnh \u1ea3nh \u0111\u1ecbnh d\u1ea1ng png s\u1ebd \u0111\u01b0\u1ee3c xu\u1ea5t ra \u1edf c\u00f9ng v\u1ecb tr\u00ed v\u1edbi bi\u1ec3u t\u01b0\u1ee3ng g\u1ed1c.<br \/>\n<img src=\"https:\/\/chat-messenger.com\/images\/IconExtractor2.jpg\" alt=\"Nh\u1eadn bi\u1ec3u t\u01b0\u1ee3ng\" 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\">Gi\u1ea3i th\u00edch ch\u01b0\u01a1ng tr\u00ecnh m\u1eabu<\/a><\/h2>\n<p>Qu\u00e1 tr\u00ecnh tr\u00edch xu\u1ea5t c\u00e1c bi\u1ec3u t\u01b0\u1ee3ng trong Java \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n b\u1eb1ng ph\u01b0\u01a1ng ph\u00e1p sau.<\/p>\n<ol>\n<li>\n\u0110\u1eb7t giao di\u1ec7n cho Windows.<br \/>\nUIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());<\/p>\n<\/li>\n<li>\nT\u1ec7p thu \u0111\u01b0\u1ee3c b\u1eb1ng c\u00e1ch k\u00e9o v\u00e0 th\u1ea3 <strong>javax.swing.JFileChooser.getIcon()<\/strong> v\u1edbi ph\u01b0\u01a1ng ph\u00e1p <strong>javax.swing.Icon<\/strong> Chuy\u1ec3n \u0111\u1ed5i th\u00e0nh \u0111\u1ed1i t\u01b0\u1ee3ng.<\/p>\n<\/li>\n<li>\n<strong>javax.imageio.ImageIO.write()<\/strong> Xu\u1ea5t \u0111\u1ed1i t\u01b0\u1ee3ng Bi\u1ec3u t\u01b0\u1ee3ng th\u00e0nh t\u1ec7p h\u00ecnh \u1ea3nh \u0111\u1ecbnh d\u1ea1ng png b\u1eb1ng ph\u01b0\u01a1ng th\u1ee9c.<\/p>\n<\/li>\n<\/ol>\n<h2 class=\"common_title\"><a name=\"3\">ch\u01b0\u01a1ng tr\u00ecnh m\u1eabu<\/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>nh\u1eadp javax.imageio.ImageIO;<br \/>\nnh\u1eadp javax.swing.ImageIcon;<br \/>\nnh\u1eadp javax.swing.JFileChooser;<br \/>\nnh\u1eadp javax.swing.JFrame;<br \/>\nnh\u1eadp javax.swing.JLabel;<br \/>\nnh\u1eadp javax.swing.JPanel;<br \/>\nnh\u1eadp javax.swing.SwingConstants;<br \/>\nnh\u1eadp javax.swing.UIManager;<\/p>\n<p>l\u1edbp c\u00f4ng khai IconExtractor m\u1edf r\u1ed9ng JFrame<br \/>\n                tri\u1ec3n khai DropTargetListener {<\/p>\n<p>    JPanel ri\u00eang t\u01b0 jContentPane = null;<br \/>\n    JLabel ri\u00eang t\u01b0 jLabel = null;<br \/>\n    tr\u00ecnh ch\u1ecdn JFileChooser ri\u00eang t\u01b0;<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        Tr\u00ecnh tr\u00edch xu\u1ea5t IconExtractor = new IconExtractor();<br \/>\n        extractor.setVisible(true);<br \/>\n    }<\/p>\n<p>    c\u00f4ng khai IconExtractor() {<br \/>\n        si\u00eau();<br \/>\n        th\u1eed {<br \/>\n            UIManager.setLookAndFeel(<br \/>\n                    UIManager.getSystemLookAndFeelClassName());<br \/>\n            tr\u00ecnh ch\u1ecdn = JFileChooser m\u1edbi();<br \/>\n        } b\u1eaft (Ngo\u1ea1i l\u1ec7 e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n        kh\u1edfi t\u1ea1o();<br \/>\n    }<\/p>\n<p>    kh\u1edfi t\u1ea1o kho\u1ea3ng tr\u1ed1ng ri\u00eang t\u01b0 () {<br \/>\n        this.setSize(300, 200);<br \/>\n        this.setContentPane(getJContentPane());<br \/>\n        this.setTitle(\u201cTr\u00edch xu\u1ea5t bi\u1ec3u t\u01b0\u1ee3ng\u201d);<br \/>\n        this.setLocationRelativeTo(null);<br \/>\n        this.setDefaultCloseOperation(EXIT_ON_CLOSE);<br \/>\n    }<\/p>\n<p>    JPanel ri\u00eang t\u01b0 getJContentPane() {<br \/>\n        n\u1ebfu (jContentPane == null) {<br \/>\n            jLabel = JLabel m\u1edbi();<br \/>\n            jLabel.setText(\u201cK\u00e9o bi\u1ec3u t\u01b0\u1ee3ng.\u201d);<br \/>\n            jLabel.setBackground(Color.white);<br \/>\n            jLabel.setHorizontalAlignment(SwingConstants.CENTER);<br \/>\n            jLabel.setOpaque(true);<br \/>\n            DropTarget m\u1edbi (jLabel,<br \/>\n                    DnDConstants.ACTION_COPY_OR_MOVE, c\u00e1i n\u00e0y);<br \/>\n            jContentPane = JPanel m\u1edbi();<br \/>\n            jContentPane.setLayout(new BorderLayout());<br \/>\n            jContentPane.add(jLabel, BorderLayout.CENTER);<br \/>\n        }<br \/>\n        tr\u1ea3 v\u1ec1 jContentPane;<br \/>\n    }<\/p>\n<p>    \/\/ \u2014 tri\u1ec3n khai DropTargetListener \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014-<br \/>\n    th\u1ea3 kho\u1ea3ng tr\u1ed1ng c\u00f4ng khai (DropTargetDropEvent dtde) {<br \/>\n        dtde.acceptDrop(DnDConstants.ACTION_MOVE);<br \/>\n        th\u1eed {<\/p>\n<p>            C\u00f3 th\u1ec3 chuy\u1ec3n nh\u01b0\u1ee3ng tran = dtde.getTransferable();<\/p>\n<p>            List fileList = (List) tran<br \/>\n                    .getTransferData(DataFlavor.javaFileListFlavor);<br \/>\n            Iterator iterator = fileList.iterator();<br \/>\n            trong khi (iterator.hasNext()) {<br \/>\n                File file = (File) iterator.next();<br \/>\n                Bi\u1ec3u t\u01b0\u1ee3ng ImageIcon = (ImageIcon) chooser.getIcon(file);<br \/>\n                Chu\u1ed7i ext = file.getAbsoluteFile() + \u201c.png\u201d;<br \/>\n                \/\/ L\u01b0u t\u1eadp tin h\u00ecnh \u1ea3nh<br \/>\n                ImageIO.write((BufferedImage) icon.getImage(), \u201cpng\u201d,<br \/>\n                        T\u1ec7p m\u1edbi (ext));<br \/>\n                jLabel.setText(&ldquo;&lt;html&gt;Tr&iacute;ch xu\u1ea5t ho&agrave;n t\u1ea5t&lt;br&gt;&rdquo; + m&aacute;y l\u1ebb);<br \/>\n                setIconImage(icon.getImage());<br \/>\n            }<br \/>\n            dtde.dropComplete(true);<br \/>\n        } b\u1eaft (Ngo\u1ea1i l\u1ec7 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>Tr\u00edch xu\u1ea5t bi\u1ec3u t\u01b0\u1ee3ng h\u1ec7 th\u1ed1ng Java Tr\u00edch xu\u1ea5t bi\u1ec3u t\u01b0\u1ee3ng c\u1ee7a t\u1ec7p \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh th\u00e0nh t\u1ec7p h\u00ecnh \u1ea3nh \u0111\u1ecbnh d\u1ea1ng png b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng Java [\u2026]<\/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\/vi\/wp-json\/wp\/v2\/posts\/975"}],"collection":[{"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/comments?post=975"}],"version-history":[{"count":5,"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/posts\/975\/revisions"}],"predecessor-version":[{"id":1872,"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/posts\/975\/revisions\/1872"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/media?parent=975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/categories?post=975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/tags?post=975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}