資源描述:
《java gui布局綜合實(shí)例》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、package布局管理器綜合實(shí)例;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={"網(wǎng)0","格1","布2","局3","管4","理器5"};privateJButton
3、gridButton[]=newJButton[grid.length];privatefinalString[]flow={"流","式","布","局","管","理","器"};privateJButtonflowButton[]=newJButton[flow.length];privatefinalString[]border={"邊界","布局","管","理","器"};privateJButtonborderButton[]=newJButton[flow.length];//鍵的按鈕,數(shù)組JBu
4、ttonbt=newJButton("卡片切換");JButtonbt1=newJButton("網(wǎng)格包布局");//構(gòu)造函數(shù)publicLayoutDemo(){super();init();//初始化this.setBackground(Color.YELLOW);//this.setTitle("布局管理器綜合實(shí)例");this.setLocation(500,300);//設(shè)置在屏幕上顯示的位置//this.setResizable(false);//設(shè)置計(jì)算器大小不可改變this.pack();//使計(jì)
5、算器中各組件大小合適}//初始化函數(shù)privatevoidinit(){JPanelGridpanel=newJPanel();//網(wǎng)格布局面板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