{"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":"lay-bieu-tuong-he-thong","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/vi\/blog\/java\/get-system-icon","title":{"rendered":"Tr\u00edch xu\u1ea5t c\u00e1c 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>Chi\u1ebft xu\u1ea5t<\/a><\/h2>\n<p>\n<strong>Java<\/strong>\u0110\u00e2y l\u00e0 m\u1ed9t ch\u01b0\u01a1ng tr\u00ecnh m\u1eabu tr\u00edch xu\u1ea5t bi\u1ec3u t\u01b0\u1ee3ng t\u1eeb m\u1ed9t t\u1ec7p \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh th\u00e0nh t\u1ec7p h\u00ecnh \u1ea3nh PNG. T\u1ec7p \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh c\u00f3 th\u1ec3 l\u00e0 b\u1ea5t k\u1ef3 lo\u1ea1i t\u1ec7p n\u00e0o, bao g\u1ed3m c\u1ea3 c\u00e1c t\u1ec7p th\u1ef1c thi c\u00f3 ph\u1ea7n m\u1edf r\u1ed9ng nh\u01b0 .exe, c\u0169ng nh\u01b0 .dll, .xls, .doc, v.v.<\/p>\n<p>T\u00f4i \u0111\u00e3 t\u00ecm ki\u1ebfm tr\u00ean internet c\u00e1c ph\u01b0\u01a1ng ph\u00e1p t\u01b0\u01a1ng t\u1ef1, nh\u01b0ng kh\u00f4ng t\u00ecm th\u1ea5y ph\u01b0\u01a1ng ph\u00e1p n\u00e0o.<br \/>\nTuy nhi\u00ean, t\u00f4i \u0111\u00e3 t\u00ecm ra m\u1ed9t c\u00e1ch r\u1ea5t d\u1ec5 \u0111\u1ec3 c\u00f3 \u0111\u01b0\u1ee3c n\u00f3, v\u00ec v\u1eady t\u00f4i s\u1ebd chia s\u1ebb v\u1edbi b\u1ea1n.<br \/>\nXin l\u01b0u \u00fd r\u1eb1ng Chat&amp;Messenger kh\u00f4ng s\u1eed d\u1ee5ng ph\u01b0\u01a1ng ph\u00e1p n\u00e0y.<a href=\"\/vi\/thu-cong\/messenger_chat\/dinh_note\/\"><strong>T\u00ednh n\u0103ng \u0111\u00ednh k\u00e8m t\u1ec7p v\u00e0o ghi ch\u00fa d\u00e1n.<\/strong><\/a>T\u00f4i d\u00f9ng n\u00f3.\n<\/p>\n<h2 class=\"common_title\"><a name=\"1\">V\u00ed d\u1ee5 v\u1ec1 x\u00e1c minh ho\u1ea1t \u0111\u1ed9ng c\u1ee7a ch\u01b0\u01a1ng tr\u00ecnh<\/a><\/h2>\n<p><a href=\"http:\/\/hp.vector.co.jp\/authors\/VA045104\/swing_ex\/IconExtractor.jar\"><strong>Ch\u1ea1y v\u00ed d\u1ee5<\/strong><\/a><br \/>\n<br \/><span style=\"font-size:x-small;\">*Thao t\u00e1c n\u00e0y c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c th\u1ef1c thi n\u1ebfu c\u00f3 t\u1ec7p JAR \u0111\u01b0\u1ee3c li\u00ean k\u1ebft v\u1edbi n\u00f3.<\/span><\/p>\n<ol>\n<li>L\u1ea5y m\u00e3 ngu\u1ed3n m\u1eabu, bi\u00ean d\u1ecbch v\u00e0 ch\u1ea1y n\u00f3.\n<\/li>\n<li>Khi b\u1ea1n kh\u1edfi ch\u1ea1y \u1ee9ng d\u1ee5ng, c\u1eeda s\u1ed5 ch\u00ednh s\u1ebd hi\u1ec7n ra. Ch\u1ec9 c\u1ea7n k\u00e9o v\u00e0 th\u1ea3 c\u00e1c bi\u1ec3u t\u01b0\u1ee3ng b\u1ea1n mu\u1ed1n tr\u00edch xu\u1ea5t v\u00e0o c\u1eeda s\u1ed5 n\u00e0y.<br \/>\n<img decoding=\"async\" src=\"https:\/\/chat-messenger.com\/images\/IconExtractor.jpg\" alt=\"T\u1ea3i bi\u1ec3u t\u01b0\u1ee3ng\" border=\"0\"><\/p>\n<\/li>\n<li>T\u1ec7p h\u00ecnh \u1ea3nh PNG s\u1ebd \u0111\u01b0\u1ee3c l\u01b0u v\u00e0o c\u00f9ng v\u1ecb tr\u00ed v\u1edbi bi\u1ec3u t\u01b0\u1ee3ng g\u1ed1c.<br \/>\n<img decoding=\"async\" src=\"https:\/\/chat-messenger.com\/images\/IconExtractor2.jpg\" alt=\"T\u1ea3i 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 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 ng\u01b0\u1eddi d\u00f9ng th\u00e0nh Windows.<br \/>\nUIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());<\/p>\n<\/li>\n<li>\nC\u00e1c t\u1ec7p \u0111\u01b0\u1ee3c l\u1ea5y b\u1eb1ng thao t\u00e1c k\u00e9o v\u00e0 th\u1ea3 <strong>javax.swing.JFileChooser.getIcon()<\/strong> Ph\u01b0\u01a1ng ph\u00e1p <strong>javax.swing.Icon<\/strong> Chuy\u1ec3n \u0111\u1ed5i n\u00f3 th\u00e0nh m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng.<\/p>\n<\/li>\n<li>\n<strong>javax.imageio.ImageIO.write()<\/strong> Ph\u01b0\u01a1ng ph\u00e1p n\u00e0y xu\u1ea5t \u0111\u1ed1i t\u01b0\u1ee3ng Icon ra t\u1ec7p h\u00ecnh \u1ea3nh PNG.<\/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>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 chooser;<\/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        si\u00eau();<br \/>\n        th\u1eed {<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        kh\u1edfi t\u1ea1o();<br \/>\n    }<\/p>\n<p>    private void initialize() {<br \/>\n        this.setSize(300, 200);<br \/>\n        this.setContentPane(getJContentPane());<br \/>\n        this.setTitle(&quot;Tr\u00edch xu\u1ea5t bi\u1ec3u t\u01b0\u1ee3ng&quot;);<br \/>\n        this.setLocationRelativeTo(null);<br \/>\n        this.setDefaultCloseOperation(EXIT_ON_CLOSE);<br \/>\n    }<\/p>\n<p>    private JPanel getJContentPane() {<br \/>\n        n\u1ebfu (jContentPane == null) {<br \/>\n            jLabel = new JLabel();<br \/>\n            jLabel.setText(&quot;Vui l\u00f2ng k\u00e9o bi\u1ec3u t\u01b0\u1ee3ng.&quot;);<br \/>\n            jLabel.setBackground(Color.white);<br \/>\n            jLabel.setHorizontalAlignment(SwingConstants.CENTER);<br \/>\n            jLabel.setOpaque(true);<br \/>\n            new DropTarget(jLabel,<br \/>\n                    DnDConstants.ACTION_COPY_OR_MOVE, this);<br \/>\n            jContentPane = new JPanel();<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    public void drop(DropTargetDropEvent dtde) {<br \/>\n        dtde.acceptDrop(DnDConstants.ACTION_MOVE);<br \/>\n        th\u1eed {<\/p>\n<p>            Transferable 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                ImageIcon icon = (ImageIcon) chooser.getIcon(file);<br \/>\n                Chu\u1ed7i ext = file.getAbsoluteFile() + \u201c.png\u201d;<br \/>\n                \/\/ L\u01b0u t\u1ec7p 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;Qu&aacute; tr&igrave;nh nh\u1ed5 r\u0103ng \u0111&atilde; ho&agrave;n t\u1ea5t.&lt;br&gt;&rdquo; + ext);<br \/>\n                setIconImage(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\/vi\/wp-json\/wp\/v2\/posts\/975","targetHints":{"allow":["GET"]}}],"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":"trang web","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}