{"id":756,"date":"2015-06-03T17:55:46","date_gmt":"2015-06-03T09:55:46","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=756"},"modified":"2026-08-18T12:09:35","modified_gmt":"2026-08-18T04:09:35","slug":"%e6%a1%86%e6%9e%b6%e7%aa%97%e5%8f%a3%e5%9f%ba%e7%a1%80","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=756","title":{"rendered":"\u6846\u67b6\u7a97\u53e3\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;\">\u7a97\u53e3\u662f GUI \u7f16\u7a0b\u7684\u57fa\u7840\u3002\u5c0f\u5e94\u7528\u7a0b\u5e8f\u6216\u56fe\u5f62\u754c\u9762\u5e94\u7528\u7a0b\u5e8f\u7684\u53ef\u89c6\u7ec4\u4ef6\u90fd\u653e\u5728\u7a97\u53e3\u4e2d\u3002\u5728 GUI \u91cc\uff0c\u7a97\u53e3\u662f\u7528\u6237\u5c4f\u5e55\u7684\u4e00\u90e8\u5206\uff0c\u8d77\u7740\u300c\u5c4f\u5e55\u4e2d\u7684\u5c0f\u5c4f\u5e55\u300d\u7684\u4f5c\u7528\u3002\u5e38\u89c1\u6709\u4e09\u79cd\u7a97\u53e3\u3002<\/p>\n<p><!--more--><\/p>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section><strong style=\"color: #4870ac;\">Applet \u7a97\u53e3<\/strong>\uff1a\u7531 Applet \u7c7b\u7ba1\u7406\uff0c\u7a0b\u5e8f\u542f\u52a8\u65f6\u7531\u7cfb\u7edf\u521b\u5efa\u548c\u5904\u7406\u3002<\/section>\n<\/li>\n<li>\n<section><strong style=\"color: #4870ac;\">\u6846\u67b6\u7a97\u53e3\uff08JFrame\uff09<\/strong>\uff1a\u901a\u5e38\u610f\u4e49\u4e0a\u7684\u7a97\u53e3\uff0c\u6709\u8fb9\u6846\u3001\u6807\u9898\u680f\uff0c\u4ee5\u53ca\u6700\u5c0f\u5316\u3001\u6700\u5927\u5316\u3001\u5173\u95ed\u6309\u94ae\u3002<\/section>\n<\/li>\n<li>\n<section><strong style=\"color: #4870ac;\">\u65e0\u8fb9\u6846\u7a97\u53e3\uff08JWindow\uff09<\/strong>\uff1a\u6ca1\u6709\u6807\u9898\u680f\u548c\u6846\u67b6\uff0c\u53ea\u662f\u4e00\u4e2a\u7a7a\u77e9\u5f62\u3002<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">\u7528 Swing \u7684 JFrame \u7c7b\u6216\u5176\u5b50\u7c7b\u521b\u5efa\u7684\u5bf9\u8c61\u5c31\u662f JFrame \u7a97\u53e3\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\u3001JFrame \u5e38\u7528\u65b9\u6cd5<\/h2>\n<p style=\"margin: 1em 0px;\">\u4e3b\u8981\u6784\u9020\u65b9\u6cd5\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;\">JFrame()<\/code> \u521b\u5efa\u65e0\u6807\u9898\u7a97\u53e3\uff1b<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(String s)<\/code> \u521b\u5efa\u6807\u9898\u4e3a s \u7684\u7a97\u53e3\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;\">\u65b9\u6cd5<\/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;\">\u4f5c\u7528<\/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;\">setBounds(x, y, width, height)<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u4f4d\u7f6e\u4e0e\u5bbd\u9ad8\uff0c\u5355\u4f4d\u50cf\u7d20<\/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;\">setSize(width, height)<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u8bbe\u7f6e\u7a97\u53e3\u5927\u5c0f<\/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;\">setBackground(Color c)<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u80cc\u666f\u989c\u8272<\/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;\">setVisible(boolean b)<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u53ef\u89c1\u6027\uff1bJFrame \u9ed8\u8ba4\u4e0d\u53ef\u89c1<\/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;\">pack()<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7d27\u51d1\u663e\u793a\uff1b\u5426\u5219\u521d\u59cb\u53ef\u80fd\u770b\u4e0d\u5230\u7ec4\u4ef6<\/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;\">setTitle \/ getTitle<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u8bbe\u7f6e \/ \u83b7\u53d6\u7a97\u53e3\u6807\u9898<\/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;\">setResizable(boolean m)<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u662f\u5426\u53ef\u8c03\u6574\u5927\u5c0f\uff08\u539f\u6587 setResiable \u4e3a\u7b14\u8bef\uff09<\/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\u600e\u6837\u5f80\u7a97\u53e3\u52a0\u7ec4\u4ef6<\/h2>\n<p style=\"margin: 1em 0px;\">Swing \u91cc\u9664 JPanel \u53ca\u5176\u5b50\u7c7b\u4e4b\u5916\uff0c\u5176\u4ed6\u5bb9\u5668\u4e0d\u5141\u8bb8\u628a\u7ec4\u4ef6\u76f4\u63a5\u52a0\u5165\u3002\u5e38\u7528\u4e24\u79cd\u505a\u6cd5\uff1a\u4e00\u662f <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;\">getContentPane()<\/code> \u62ff\u5230\u5185\u5bb9\u9762\u677f\u518d add\uff1b\u4e8c\u662f\u5efa\u4e00\u4e2a JPanel \u4e2d\u95f4\u5bb9\u5668\uff0c\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;\">setContentPane()<\/code> \u628a\u5b83\u8bbe\u6210\u5185\u5bb9\u9762\u677f\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">mw.getContentPane().add(button);\n\nJPanel contentPane = new JPanel();\nmw.setContentPane(contentPane);<\/code><\/pre>\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\u4e24\u4e2a\u7a97\u53e3\u793a\u4f8b<\/h2>\n<p style=\"margin: 1em 0px;\">\u3010\u4f8b 11-1\u3011\u7528 JFrame \u521b\u5efa\u4e00\u4e2a\u53ea\u6709\u4e00\u4e2a\u6309\u94ae\u7684\u7a97\u53e3\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">import javax.swing.*;\npublic class Example5_1 {\n    public static void main(String args[]) {\n        JFrame mw = new JFrame(\"\u6211\u7684\u7b2c\u4e00\u4e2a\u7a97\u53e3\");\n        mw.setSize(250, 200);\n        JButton button = new JButton(\"\u6211\u662f\u4e00\u4e2a\u6309\u94ae\");\n        mw.getContentPane().add(button);\n        mw.setVisible(true);\n    }\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u7528 Swing \u5199 GUI \u65f6\uff0c\u901a\u5e38\u4e0d\u76f4\u63a5 new JFrame\uff0c\u800c\u7528\u6d3e\u751f\u5b50\u7c7b\uff0c\u65b9\u4fbf\u52a0\u5165\u7279\u5b9a\u8981\u6c42\u548c\u5185\u5bb9\u3002\u3010\u4f8b 11-2\u3011\u7528\u5b50\u7c7b MyWindowDemo \u521b\u5efa\u4e24\u4e2a\u7c7b\u4f3c\u7a97\u53e3\u3002\u539f\u6587 <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 static butt1<\/code> \u65e0\u6cd5\u7f16\u8bd1\uff0c\u5df2\u6539\u4e3a\u666e\u901a\u5c40\u90e8\u53d8\u91cf\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">import javax.swing.*;\nimport java.awt.*;\npublic class Example5_2 {\n    public static MyWindowDemo mw1;\n    public static MyWindowDemo mw2;\n    public static void main(String args[]) {\n        JButton butt1 = new JButton(\"\u6211\u662f\u4e00\u4e2a\u6309\u94ae\");\n        String name1 = \"\u6211\u7684\u7b2c\u4e00\u4e2a\u7a97\u53e3\";\n        String name2 = \"\u6211\u7684\u7b2c\u4e8c\u4e2a\u7a97\u53e3\";\n        mw1 = new MyWindowDemo(name1, butt1, Color.blue, 350, 450);\n        mw1.setVisible(true);\n        JButton butt2 = new JButton(\"\u6211\u662f\u53e6\u4e00\u4e2a\u6309\u94ae\");\n        mw2 = new MyWindowDemo(name2, butt2, Color.magenta, 300, 400);\n        mw2.setVisible(true);\n    }\n}\nclass MyWindowDemo extends JFrame {\n    public MyWindowDemo(String name, JButton button, Color c, int w, int h) {\n        super();\n        setTitle(name);\n        setSize(w, h);\n        Container con = getContentPane();\n        con.add(button);\n        con.setBackground(c);\n    }\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u663e\u793a\u989c\u8272\u7531 java.awt \u5305\u7684 Color \u7c7b\u7ba1\u7406\uff0c\u9884\u5b9a\u4e86\u4e00\u4e9b\u5e38\u7528\u989c\u8272\uff0c\u89c1\u8868 11-3\u3002JFrame \u90e8\u5206\u5e38\u7528\u65b9\u6cd5\u89c1\u8868 11-4\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/06\/113.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-757\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/06\/113.png\" alt=\"113\" width=\"314\" height=\"510\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/06\/114.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-758\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/06\/114.png\" alt=\"114\" width=\"534\" height=\"332\" srcset=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/06\/114.png 627w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/06\/114-528x328.png 528w\" sizes=\"(max-width: 534px) 100vw, 534px\" \/><\/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\uff1aJFrame \u9ed8\u8ba4\u770b\u4e0d\u89c1\uff0c\u8981 setVisible(true)\uff1b\u7ec4\u4ef6\u52a0\u5230\u5185\u5bb9\u9762\u677f\u4e0a\uff0c\u65e5\u5e38\u7528\u5b50\u7c7b\u5c01\u88c5\u6807\u9898\u3001\u5c3a\u5bf8\u548c\u80cc\u666f\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u7a97\u53e3\u662f GUI \u7f16\u7a0b\u7684\u57fa\u7840\u3002\u5c0f\u5e94\u7528\u7a0b\u5e8f\u6216\u56fe\u5f62\u754c\u9762\u5e94\u7528\u7a0b\u5e8f\u7684\u53ef\u89c6\u7ec4\u4ef6\u90fd\u653e\u5728\u7a97\u53e3\u4e2d\u3002\u5728 GUI \u91cc\uff0c\u7a97\u53e3\u662f\u7528\u6237\u5c4f\u5e55 [&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\/756"}],"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=756"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/756\/revisions"}],"predecessor-version":[{"id":760,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/756\/revisions\/760"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=756"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=756"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=756"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}