欢迎来到天天文库
浏览记录
ID:11479797
大小:64.00 KB
页数:0页
时间:2018-07-12
《java gui布局综合实例》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、package布局管理器综合实例;importjava.awt.*;importjava.awt.FlowLayout;importjava.awt.CardLayout;importjava.awt.GridBagLayout;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;
2、importjava.awt.event.*;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.JTextField;publicclassLayoutDemoextendsJFrameimplementsActionListener{privatefinalString[]grid={"网0","格1","布2","局3","管4","理器5"};privateJButton
3、gridButton[]=newJButton[grid.length];privatefinalString[]flow={"流","式","布","局","管","理","器"};privateJButtonflowButton[]=newJButton[flow.length];privatefinalString[]border={"边界","布局","管","理","器"};privateJButtonborderButton[]=newJButton[flow.length];//键的按钮,数组JBu
4、ttonbt=newJButton("卡片切换");JButtonbt1=newJButton("网格包布局");//构造函数publicLayoutDemo(){super();init();//初始化this.setBackground(Color.YELLOW);//this.setTitle("布局管理器综合实例");this.setLocation(500,300);//设置在屏幕上显示的位置//this.setResizable(false);//设置计算器大小不可改变this.pack();//使计
5、算器中各组件大小合适}//初始化函数privatevoidinit(){JPanelGridpanel=newJPanel();//网格布局面板4Gridpanel.setLayout(newGridLayout(2,3,3,3));for(inti=0;i6、LUE);}JPanelFlowpanel=newJPanel();//流式布局面板Flowpanel.setLayout(newFlowLayout());for(inti=0;i7、界布局面板Borderpanel.setLayout(newBorderLayout());for(inti=0;i8、rpanel.add("South",borderButton[2]);Borderpanel.add("West",borderButton[3]);Borderpanel.add("Center",borderButton[4]);JPanelCardpanel=newJPanel();//卡片布局面板Cardpanel.setLayout(newBorderLayo
6、LUE);}JPanelFlowpanel=newJPanel();//流式布局面板Flowpanel.setLayout(newFlowLayout());for(inti=0;i7、界布局面板Borderpanel.setLayout(newBorderLayout());for(inti=0;i8、rpanel.add("South",borderButton[2]);Borderpanel.add("West",borderButton[3]);Borderpanel.add("Center",borderButton[4]);JPanelCardpanel=newJPanel();//卡片布局面板Cardpanel.setLayout(newBorderLayo
7、界布局面板Borderpanel.setLayout(newBorderLayout());for(inti=0;i8、rpanel.add("South",borderButton[2]);Borderpanel.add("West",borderButton[3]);Borderpanel.add("Center",borderButton[4]);JPanelCardpanel=newJPanel();//卡片布局面板Cardpanel.setLayout(newBorderLayo
8、rpanel.add("South",borderButton[2]);Borderpanel.add("West",borderButton[3]);Borderpanel.add("Center",borderButton[4]);JPanelCardpanel=newJPanel();//卡片布局面板Cardpanel.setLayout(newBorderLayo
此文档下载收益归作者所有