



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
package 布局管理器综合实例;import java.awt.*;import java.awt.FlowLayout;import java.awt.CardLayout;import java.awt.GridBagLayout;import java.awt.BorderLayout;import java.awt.Color;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.*;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JTextField;public class LayoutDemo extends JFrame implements ActionListener private final Stringgrid=网0,格1,布2,局3, 管4,理器5;private JButton gridButton=new JButtongrid.length;private final Stringflow=流,式,布,局, 管,理,器;private JButton flowButton=new JButtonflow.length;private final Stringborder=边界,布局,管,理,器;private JButton borderButton=new JButtonflow.length;/键的按钮 ,数组JButton bt=new JButton(卡片切换);JButton bt1=new JButton(网格包布局);/构造函数public LayoutDemo()super();init();/初始化this.setBackground(Color.YELLOW);/this.setTitle(布局管理器综合实例);this.setLocation(500,300);/设置在屏幕上显示的位置/this.setResizable(false);/设置计算器大小不可改变this.pack();/使计算器中各组件大小合适/初始化函数private void init()JPanel Gridpanel=new JPanel();/网格布局面板Gridpanel.setLayout( new GridLayout(2,3,3,3);for(int i=0;igrid.length;i+)/生成按钮,并添加到面板中gridButtoni=new JButton(gridi);Gridpanel.add(gridButtoni);gridButtoni.setForeground(Color.BLUE);JPanel Flowpanel=new JPanel();/流式布局面板Flowpanel.setLayout( new FlowLayout();for(int i=0;iflow.length;i+)/生成按钮,并添加到面板中flowButtoni=new JButton(flowi);Flowpanel.add(flowButtoni);flowButtoni.setForeground(Color.RED);JPanel Borderpanel=new JPanel();/边界布局面板Borderpanel.setLayout( new BorderLayout();for(int i=0;iborder.length;i+)/生成按钮,并添加到面板中borderButtoni=new JButton(borderi);borderButtoni.setForeground(Color.CYAN);Borderpanel.add(North,borderButton0);Borderpanel.add(East,borderButton1);Borderpanel.add(South,borderButton2);Borderpanel.add(West,borderButton3);Borderpanel.add(Center,borderButton4);JPanel Cardpanel=new JPanel();/卡片布局面板Cardpanel.setLayout(new BorderLayout();JPanel cp=new JPanel();JButton bt=new JButton(卡片切换);bt.addActionListener(this);cp.add(bt);Cardpanel.add(North,cp);JPanel p1=new JPanel();p1.add(new JButton(Button 1);p1.add(new JButton(Button 2);p1.add(new JButton(Button 3);JPanel p2=new JPanel();p2.add(new TextField(TextField,20); JPanel Cards=new JPanel();CardLayout Layout=new CardLayout();Cards.setLayout( Layout);Cards.add(Panel with Buttons,p1);Cards.add(Panel with TextField,p2);Cardpanel.add(Center,Cards);JPanel GridBagpanel=new JPanel();/网格包GridBagpanel.setLayout( new GridBagLayout();GridBagConstraints c=new GridBagConstraints();c.fill=GridBagConstraints.BOTH;c.weightx=1.0;GridBagpanel.add(new JButton(网1),c);GridBagpanel.add(new JButton(格2),c);GridBagpanel.add(new JButton(包3),c);c.gridwidth=GridBagConstraints.REMAINDER;GridBagpanel.add(new JButton(布4),c);c.weightx=0.0;GridBagpanel.add(new JButton(局5),c);c.gridwidth=GridBagConstraints.RELATIVE;GridBagpanel.add(new JButton(管6),c);c.gridwidth=GridBagConstraints.REMAINDER;GridBagpanel.add(new JButton(理7),c);c.gridheight=2;c.gridwidth=1;c.weighty=1.0;GridBagpanel.add(new JButton(器8),c);c.weighty=0.0;c.gridwidth=GridBagConstraints.REMAINDER;c.gridheight=1;GridBagpanel.add(new JButton(器9),c);GridBagpanel.add(new JButton(器0),c); getContentPane().setLayout(new BorderLayout(); getContentPane().add(North,Flowpanel); getContentPane().add(West,GridBagpanel); getContentPane().add(Center,Borderpanel); getContentPane().add(East,Cardpanel); getContentPane().add(South,Gridpanel); public void actionPerformed(A
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年河北承德辰飞供电服务有限公司招聘101人考前自测高频考点模拟试题带答案详解
- 2025湖北恩施州宣恩县园投人力资源服务有限公司招聘多家企业工作人员14人模拟试卷及答案详解(有一套)
- 2025年肠胃病学消化系统疾病内镜检查评估答案及解析
- 2025年儿科学院新生儿肺炎临床表现与鉴别诊断模拟考试卷答案及解析
- 2025年眩晕症诊断与治疗方案选择考核卷答案及解析
- 2025年内分泌学内分泌疾病药物治疗解析答案及解析
- 2025贵州瓮安县瓮水街道招聘公益性岗位人员20人模拟试卷有答案详解
- 2025北京市环科院编制外人员招聘6人模拟试卷及答案详解(考点梳理)
- 2025年心血管内科心肌梗死急救流程模拟考核试卷答案及解析
- 2025年皮肤科常见疾病知识检测考题答案及解析
- 生产主管转正工作总结
- 2025至2030中国高纯铝行业发展趋势与行业发展研究与产业战略规划分析评估报告
- 会务理论考试题及答案
- 国家开放大学电大《课程与教学论》形考任务3试题及答案
- 商务英语口语900句
- 辽宁省沈阳市基层诊所医疗机构卫生院社区卫生服务中心村卫生室名单目录信息
- 锅炉空预器清洗方案
- SF∕T 0111-2021 法医临床检验规范
- 药敏试验结果的解读
- DB14∕T 1319-2021 公路工程标准工程量清单及计量规范
- 冶金行业应用产品介绍(应用)
评论
0/150
提交评论