{"id":751,"date":"2015-06-03T17:51:52","date_gmt":"2015-06-03T09:51:52","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=751"},"modified":"2026-08-18T12:09:34","modified_gmt":"2026-08-18T04:09:34","slug":"java%e5%9b%be%e5%bd%a2%e7%95%8c%e9%9d%a2%e8%ae%be%e8%ae%a1%e5%9f%ba%e7%a1%80","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=751","title":{"rendered":"Java\u56fe\u5f62\u754c\u9762\u8bbe\u8ba1\u57fa\u7840"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\">\u65e9\u5148\u7a0b\u5e8f\u7528\u6700\u7b80\u5355\u7684\u8f93\u5165\u8f93\u51fa\uff1a\u7528\u6237\u5728\u952e\u76d8\u8f93\u5165\uff0c\u7a0b\u5e8f\u628a\u4fe1\u606f\u6253\u5728\u5c4f\u5e55\u4e0a\u3002\u73b0\u4ee3\u7a0b\u5e8f\u8981\u6c42\u56fe\u5f62\u7528\u6237\u754c\u9762\uff08<strong style=\"color: #4870ac;\">GUI<\/strong>\uff0cGraphical User Interface\uff09\uff0c\u754c\u9762\u91cc\u6709\u83dc\u5355\u3001\u6309\u94ae\uff0c\u7528\u6237\u7528\u9f20\u6807\u70b9\u9009\u9879\u3001\u70b9\u6309\u94ae\u6765\u9a71\u52a8\u529f\u80fd\u6a21\u5757\u3002<\/p>\n<p><!--more--><\/p>\n<p style=\"margin: 1em 0px;\">\u672c\u7ae0\u5b66\u4e60\u5982\u4f55\u7528 Java \u7f16\u5199 GUI \u7a0b\u5e8f\uff0c\u4ee5\u53ca\u5982\u4f55\u901a\u8fc7 GUI \u5b8c\u6210\u8f93\u5165\u548c\u8f93\u51fa\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001AWT \u548c Swing<\/h2>\n<p style=\"margin: 1em 0px;\">\u65e9\u671f\u7528\u62bd\u8c61\u7a97\u53e3\u5de5\u5177\u5305 AWT\uff08Abstract Window Toolkit\uff09\u3002\u73b0\u5728\u591a\u7528 Swing\u3002Swing \u53ef\u4ee5\u770b\u4f5c AWT \u7684\u6539\u826f\uff0c\u4e0d\u662f\u5b8c\u5168\u66ff\u4ee3\uff0c\u800c\u662f\u63d0\u9ad8\u548c\u6269\u5c55\uff0c\u5199 GUI \u65f6\u4e24\u8005\u90fd\u8981\u7528\u3002\u5b83\u4eec\u5171\u5b58\u4e8e Java \u57fa\u7840\u7c7b\uff08JFC\uff09\u4e2d\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u91cd\u8981\u5dee\u522b\uff1aAWT \u4f9d\u8d56\u4e3b\u5e73\u53f0\u7ed8\u5236\u7ec4\u4ef6\uff1bSwing \u6709\u81ea\u5df1\u7684\u673a\u5236\uff0c\u5728\u4e3b\u5e73\u53f0\u7a97\u53e3\u91cc\u7ed8\u5236\u548c\u7ba1\u7406\u7ec4\u4ef6\u3002\u6240\u4ee5\u540c\u4e00\u5957 AWT \u7a0b\u5e8f\u5728\u4e0d\u540c\u5e73\u53f0\u5916\u89c2\u53ef\u80fd\u6709\u5dee\u5f02\uff0c\u57fa\u4e8e Swing \u7684\u5e94\u7528\u5728\u5404\u5e73\u53f0\u4e0a\u66f4\u63a5\u8fd1\u540c\u4e00\u98ce\u683c\u3002<\/p>\n<p style=\"margin: 1em 0px;\">Swing \u4e2d\u7684\u7c7b\u4ece AWT \u7ee7\u627f\uff0c\u6709\u4e9b\u76f4\u63a5\u6269\u5c55\u5bf9\u5e94\u7c7b\uff0c\u4f8b\u5982 JApplet\u3001JDialog\u3001JFrame\u3001JWindow\u3002\u8bbe\u8ba1\u56fe\u5f62\u754c\u9762\u4e3b\u8981\u5f15\u5165\u4e24\u4e2a\u5305\uff1a<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">javax.swing<\/code>\uff08\u57fa\u672c\u7c7b\uff09\u548c <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">java.awt.event<\/code>\uff08\u4e8b\u4ef6\u63a5\u53e3\u548c\u7c7b\uff09\u3002<\/p>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u5bf9\u6bd4\u9879<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">AWT<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">Swing<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7ed8\u5236\u65b9\u5f0f<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u4f9d\u8d56\u4e3b\u5e73\u53f0\u7ec4\u4ef6<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u81ea\u5df1\u5728\u7a97\u53e3\u4e2d\u7ed8\u5236<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u8de8\u5e73\u53f0\u5916\u89c2<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u53ef\u80fd\u6709\u5dee\u5f02<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u66f4\u4e00\u81f4<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5178\u578b\u7a97\u53e3\u7c7b<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">Frame\u3001Window<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">JFrame\u3001JDialog\u3001JWindow<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u7ec4\u4ef6\u548c\u5bb9\u5668<\/h2>\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u7ec4\u4ef6\uff08Component\uff09<\/strong>\u662f\u56fe\u5f62\u754c\u9762\u7684\u57fa\u672c\u5143\u7d20\uff0c\u7528\u6237\u53ef\u4ee5\u76f4\u63a5\u64cd\u4f5c\uff0c\u4f8b\u5982\u6309\u94ae\u3002<strong style=\"color: #4870ac;\">\u5bb9\u5668\uff08Container\uff09<\/strong>\u662f\u590d\u5408\u5143\u7d20\uff0c\u53ef\u4ee5\u5305\u542b\u7ec4\u4ef6\uff0c\u4f8b\u5982\u9762\u677f\u3002<\/p>\n<p style=\"margin: 1em 0px;\">Java \u4e3a\u6bcf\u79cd\u7ec4\u4ef6\u9884\u5b9a\u4e49\u7c7b\uff0c\u7a0b\u5e8f\u901a\u8fc7\u5b83\u4eec\u6216\u5b50\u7c7b\u521b\u5efa\u5bf9\u8c61\uff1aSwing \u7684 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">JButton<\/code> \u5bf9\u8c61\u5c31\u662f\u6309\u94ae\u3002<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">JFrame<\/code> \u5bf9\u8c61\u5c31\u662f\u7a97\u53e3\u3002\u6240\u6709\u7ec4\u4ef6\u7684\u5171\u6709\u64cd\u4f5c\u5b9a\u4e49\u5728 Component \u8d85\u7c7b\u4e2d\uff0c\u6240\u6709\u5bb9\u5668\u7684\u5171\u6709\u64cd\u4f5c\u5b9a\u4e49\u5728 Container \u4e2d\uff0c\u4f8b\u5982\u5927\u591a\u6570\u5bb9\u5668\u90fd\u80fd\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">add()<\/code> \u6dfb\u52a0\u7ec4\u4ef6\u3002<\/p>\n<p style=\"margin: 1em 0px;\">Component\u3001Container \u548c Graphics \u662f AWT \u7684\u5173\u952e\u7c7b\u3002\u5bb9\u5668\u88ab\u5f53\u4f5c\u7279\u6b8a\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u653e\u8fdb\u53e6\u4e00\u4e2a\u5bb9\u5668\uff1a\u82e5\u5e72\u6309\u94ae\u548c\u6587\u672c\u6846\u5206\u653e\u5728\u4e24\u4e2a\u9762\u677f\uff0c\u518d\u628a\u9762\u677f\u548c\u53e6\u4e00\u4e9b\u6309\u94ae\u653e\u5165\u7a97\u53e3\u3002\u8fd9\u79cd\u5c42\u6b21\u6784\u9020\u80fd\u4ee5\u589e\u91cf\u65b9\u5f0f\u642d\u51fa\u590d\u6742\u754c\u9762\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e09\u3001\u4e8b\u4ef6\u9a71\u52a8\u7a0b\u5e8f\u8bbe\u8ba1<\/h2>\n<p style=\"margin: 1em 0px;\">\u56fe\u5f62\u754c\u9762\u4e0a\u7684<strong style=\"color: #4870ac;\">\u4e8b\u4ef6<\/strong>\u6307\u5728\u67d0\u4e2a\u7ec4\u4ef6\u4e0a\u53d1\u751f\u7684\u7528\u6237\u64cd\u4f5c\uff0c\u4f8b\u5982\u5355\u51fb\u6309\u94ae\uff0c\u8fd9\u4e2a\u6309\u94ae\u5c31\u662f\u4e8b\u4ef6\u7684\u6fc0\u53d1\u8005\u3002\u76d1\u89c6\u4e8b\u4ef6\u7684\u5bf9\u8c61\u53eb\u76d1\u89c6\u5668\uff0c\u5b83\u63d0\u4f9b\u54cd\u5e94\u65b9\u6cd5\u3002\u8981\u628a\u76d1\u89c6\u5668\u548c\u4e8b\u4ef6\u6e90\u5173\u8054\u8d77\u6765\uff0c\u9700\u8981\u5411\u4e8b\u4ef6\u5bf9\u8c61<strong style=\"color: #4870ac;\">\u6ce8\u518c\u76d1\u89c6\u5668<\/strong>\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u5b9e\u73b0\u4e8b\u4ef6\u5904\u7406\u4e3b\u8981\u6709\u4e24\u6761\u8def\uff1a\u91cd\u5199 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">handleEvent<\/code>\uff08\u5de5\u4f5c\u91cf\u8f83\u5927\uff09\uff1b\u6216\u5b9e\u73b0\u7cfb\u7edf\u63d0\u4f9b\u7684\u76d1\u542c\u63a5\u53e3\u3002java.awt.event \u6a21\u578b\u6709\u4e09\u4e2a\u7ec4\u6210\u5143\u7d20\uff1a\u6e90\u5bf9\u8c61\u3001\u76d1\u89c6\u5668\u5bf9\u8c61\u3001\u4e8b\u4ef6\u5bf9\u8c61\u3002\u6bcf\u4e2a\u6e90\u5bf9\u8c61\u7ef4\u62a4\u5df2\u6ce8\u518c\u76d1\u89c6\u5668\u5217\u8868\uff0c\u53ea\u6709\u6ce8\u518c\u4e4b\u540e\u7cfb\u7edf\u624d\u4f1a\u628a\u4e8b\u4ef6\u901a\u77e5\u76d1\u89c6\u5668\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u4ee5\u6309\u94ae\u4e3a\u4f8b\uff1aJButton \u5bf9\u8c61 button \u88ab\u70b9\u51fb\u65f6\u4ea7\u751f ActionEvent\u3002\u76d1\u89c6\u5668\u7c7b\u5fc5\u987b\u5b9e\u73b0 ActionListener\uff0c\u5199\u51fa <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">actionPerformed<\/code>\uff0c\u518d\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">addActionListener<\/code> \u6ce8\u518c\u3002\u5b9e\u9645\u70b9\u51fb\u4f1a\u4ea7\u751f\u4e00\u4e32 ChangeEvent \u548c ActionEvent\uff0c\u5e94\u7528\u7a0b\u5e8f\u901a\u5e38\u53ea\u5904\u7406\u5b8c\u6574\u6309\u4e0b\u52a8\u4f5c\u5bf9\u5e94\u7684\u90a3\u4e00\u6b21 ActionEvent\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u8868 11-1 \u7ed9\u51fa\u6709\u4ee3\u8868\u6027\u7684\u4e8b\u4ef6\u7c7b\u578b\u548c\u4ea7\u751f\u8fd9\u4e9b\u4e8b\u4ef6\u7684\u90e8\u5206 Swing \u7ec4\u4ef6\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/06\/111.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-752\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/06\/111.png\" alt=\"111\" width=\"525\" height=\"459\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u6bcf\u4e2a\u4e8b\u4ef6\u7c7b\u578b\u90fd\u6709\u76f8\u5e94\u7684\u76d1\u89c6\u5668\u63a5\u53e3\uff0c\u8868 11-2 \u5217\u51fa\u4e86\u6bcf\u4e2a\u63a5\u53e3\u7684\u65b9\u6cd5\u3002\u5b9e\u73b0\u63a5\u53e3\u7684\u7c7b\u5fc5\u987b\u5b9e\u73b0\u5176\u4e2d\u5b9a\u4e49\u7684\u5168\u90e8\u65b9\u6cd5\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/06\/112.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-753\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/06\/112.png\" alt=\"112\" width=\"531\" height=\"649\" srcset=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/06\/112.png 588w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/06\/112-528x646.png 528w\" sizes=\"(max-width: 531px) 100vw, 531px\" \/><\/a><\/p>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1aSwing \u5728 AWT \u7a97\u53e3\u91cc\u81ea\u5df1\u753b\u7ec4\u4ef6\uff1b\u5bb9\u5668\u5957\u7ec4\u4ef6\uff0c\u4e8b\u4ef6\u6e90\u6ce8\u518c\u76d1\u542c\u5668\uff0c\u70b9\u51fb\u540e\u7cfb\u7edf\u628a ActionEvent \u4ea4\u7ed9 actionPerformed\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u65e9\u5148\u7a0b\u5e8f\u7528\u6700\u7b80\u5355\u7684\u8f93\u5165\u8f93\u51fa\uff1a\u7528\u6237\u5728\u952e\u76d8\u8f93\u5165\uff0c\u7a0b\u5e8f\u628a\u4fe1\u606f\u6253\u5728\u5c4f\u5e55\u4e0a\u3002\u73b0\u4ee3\u7a0b\u5e8f\u8981\u6c42\u56fe\u5f62\u7528\u6237\u754c\u9762\uff08GUI\uff0cGraph [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[64],"tags":[43],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/751"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=751"}],"version-history":[{"count":1,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/751\/revisions"}],"predecessor-version":[{"id":754,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/751\/revisions\/754"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}