lesson17-JScrollDemo

发布时间 2023-10-27 11:01:07作者: viking97816

 

 

 

 

package zym.lesson17;

import java.awt.Button;
import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import com.sun.glass.ui.Window;

public class JScrollDemo extends JFrame{
	
	
	public JScrollDemo(){
		
		Container container=this.getContentPane();
		container.setLayout(new GridLayout(2, 1, 10, 10));//后面参数的意思,间距
		//放三个
		JPanel jPanel=new JPanel(new GridLayout(1, 3));
		jPanel.add(new Button("zym1"));
		jPanel.add(new Button("zym1"));
		jPanel.add(new Button("zym1"));
		
		//放两个
		JPanel jPane2=new JPanel(new GridLayout(1, 2));			
		jPane2.add(new Button("zym2"));
		jPane2.add(new Button("zym2")); 
		
		//放两个		
		JPanel jPane3=new JPanel(new GridLayout(2, 1));
		jPane3.add(new Button("zym3"));
		jPane3.add(new Button("zym3"));
		
		//放六个
		JPanel jPane4=new JPanel(new GridLayout(2, 3));
		
		jPane4.add(new Button("zym4"));
		jPane4.add(new Button("zym4"));
		jPane4.add(new Button("zym4"));
		jPane4.add(new Button("zym4"));
		jPane4.add(new Button("zym4"));
		jPane4.add(new Button("zym4"));		
		
		
		container.add(jPanel);
		container.add(jPane2);		
		container.add(jPane3);
		container.add(jPane4);
		
		this.setTitle("lesson17-JScrollDemo");
		this.setVisible(true);
		this.setSize(400, 300);
		this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		
		
	}
	

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new JScrollDemo();

	}

}