package com.liutong.swing.grid;
import javax.swing.;
import java.awt.;
import java.awt.event.*;
public class gridlayout extends JFrame implements ActionListener {
/**
* @param args
*/
JPanel jp1,jp2,jp3,jp4;
JButton jb1,jb2,jb3,jb4;
JLabel jl1,jl2,jl3;
CardLayout c1,c2;
public static void main(String[] args) {
// TODO Auto-generated method stub
new gridlayout();
}
//网格布局
public gridlayout(){
this.setTitle("这个是 卡片布局 这个是第一张卡片 整体是网格布局,第一个流布局,第二个是网格布局,第三个是边界布局");
//this.setLayout(new GridLayout(4,1,10,10));
c1=new CardLayout();//设置卡片布局
this.setLayout(c1);
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jp4=new JPanel();
jb4=new JButton("播放");
jb4.addActionListener(this);
jl1=new JLabel("网格布局 GridLayout");
String borderName [] = {"North","South","West","East","Center"};
String border [] = {BorderLayout.NORTH,BorderLayout.SOUTH,BorderLayout.WEST,
BorderLayout.EAST,BorderLayout.CENTER};
/*jb1=new JButton("1");
jb2=new JButton("2");
jb3=new JButton("3");
*/
jp1.setLayout(new FlowLayout(1,10,10));
jp2.setLayout(new GridLayout(4,3,3,3));
jp3.setLayout(new BorderLayout());
jp2.add(jl1);
JButton []jb=new JButton[9];
for(int i=0;i<jb.length;i++){
jb[i]=new JButton(i+1+" ");
jp2.add(jb[i]);
}
JButton []jb2=new JButton[9];
for(int i=0;i<jb2.length;i++){
jb2[i]=new JButton("流布局"+i);
jp1.add(jb2[i]);
}
jp1.add(jb4);
JButton []jb3=new JButton[5];
for(int i=0;i<jb3.length;i++){
//jb3[i]=new JButton(borderName[i]);
jp3.add(new JButton(borderName[i]),border[i]);
}
/* jb3[0]=new JButton("West");
jp3.add(jb[0],"West");*/
/*jp1.add(jb1);
jp1.add(jb2);
jp1.add(jb3);
*/
this.add(jp1,"1");
this.add(jp2,"2");
this.add(jp3,"3");
//this.add(jb4,"4");
this.setBounds(500, 500, 200, 800);//设置窗口弹出的位置和大小
this.setVisible(true);
this.setDefaultCloseOperation(1);//
/*
1.this.setDefaultCloseOperation(0);// DO_NOTHING_ON_CLOSE,不执行任何操作。
2.this.setDefaultCloseOperation(1);//HIDE_ON_CLOSE,只隐藏界面,setVisible(false)。
3.this.setDefaultCloseOperation(2);//DISPOSE_ON_CLOSE,隐藏并释放窗体,dispose(),当最后一个窗口被释放后,则程序也随之运行结束。
4.this.setDefaultCloseOperation(3);//EXIT_ON_CLOSE,直接关闭应用程序,System.exit(0)。一个main函数对应一整个程序。
*/
//this.setSize(200, 800);
}
public void actionPerformed(ActionEvent arg0){
if(arg0.getSource()==jb4){
c1.show(this.getContentPane(),"2");
}
}
}