Awt小试

import java.awt.Button;
import java.awt.Color;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class Pane extends Panel {
	Button bt01,bt02;
	TextField fle1;
	Pane()
	{
		bt01=new Button("colar1");
		bt02=new Button("color2");
		fle1=new TextField("my");
		add(bt01);
		add(fle1);
		add(bt02);
		bt01.addActionListener(new ActionListener()
		{

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				setBackground(Color.darkGray);
				
			}
			
		});
		bt02.addActionListener(new ActionListener()
		{

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				setBackground(Color.BLUE);
				
			}
			
		});
		
	}

	
	

}
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


public class Test_Layourt {//BorderLayout边界式布局

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Frame fre =new Frame("hello");
		Button bt01=new Button("south"),
				bt02=new Button("north"),
				bt03=new Button("west"),
				bt04=new Button("east"),
				bt05=new Button("centore");
		fre.add(bt01, BorderLayout.NORTH);
		fre.add(bt02, BorderLayout.SOUTH);
		fre.add(bt03, BorderLayout.WEST);
		fre.add(bt04, BorderLayout.EAST);
		fre.add(bt05, BorderLayout.CENTER);
		fre.setBounds(100, 100, 200, 200);
		fre.setVisible(true);
		fre.validate();
		fre.addWindowListener(new WindowAdapter()
		{

			@Override
			public void windowClosing(WindowEvent arg0) {
				// TODO Auto-generated method stub
				System.exit(0);
				super.windowClosing(arg0);
			}
			
		});
		      

	}

}


 

import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


public class Test_pane extends Frame {
	
	Pane pane1,pane2;
	ScrollPane scallPane;
	Test_pane()
	{
		this.setLayout(new FlowLayout());
		pane1=new Pane();
		pane2=new Pane();
		scallPane=new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);//滚动面板创建
		scallPane.add(pane1);
		scallPane.add(pane2);
		this.add(scallPane);
		
		this.addWindowListener(new WindowAdapter()
		{
			@Override
			public void windowClosing(WindowEvent e) {
				// TODO Auto-generated method stub
				System.exit(0);
				super.windowClosing(e);
			}
			
			
		}
		);
		this.setBounds(100, 100, 200, 200);
		this.setVisible(true);
		this.validate();
	}
	


   
}


 

import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;


public class Text_BoxLayout extends JFrame{
	Box box1,box2,Box1;
	Text_BoxLayout()
	{
			box1=Box.createHorizontalBox();//水平盒式布局,组件初始化
			box1.add(new Label("name"));
			box1.add(Box.createHorizontalStrut(12));//水平距离
			box1.add(new TextField(12));
			box2=Box.createHorizontalBox();
			box2.add(new Label("sex"));
			box2.add(Box.createHorizontalStrut(12));
			box2.add(new TextField(12));
			Box1=Box.createVerticalBox();
			Box1.add(box1);
			Box1.add(Box.createVerticalStrut(12));
			Box1.add(box2);
			this.addWindowListener(new WindowAdapter()
			{

				@Override
				public void windowClosing(WindowEvent arg0) {
					// TODO Auto-generated method stub
					super.windowClosing(arg0);
					System.exit(0);
				}
				
			});
			this.setLayout(new FlowLayout());
			this.setBounds(100, 100, 200, 200);
			add(Box1);
			this.setVisible(true);
			this.validate();
			
	}

}

 

 

import java.awt.Button;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;


public class Text_GrideLayout extends JFrame{
	GridLayout gride;
	Label[][] lable;
	
	Text_GrideLayout()
	{
		gride = new GridLayout(12,12);
		lable=new Label[12][12];
		this.setLayout(gride);
		for(int i=0;i<12;i++)
		{
			for(int j=1;j<12;j++)
			{
				lable[i][j]=new Label();//这个为何必须有
		
				if((i+j)%2==0)
				{
					lable[i][j].setBackground(Color.black);
					
				}
				else
				{
					lable[i][j].setBackground(Color.WHITE);
				
				}
				add(lable[i][j]);
			}
		}
		this.addWindowListener(new WindowAdapter()
		{

			@Override
			public void windowClosing(WindowEvent e) {
				// TODO Auto-generated method stub
				
				super.windowClosing(e);
				System.exit(0);
			}
			
		});
		this.setBounds(100, 100, 220, 220);
		this.setVisible(true);
		this.validate();
	}
	

}


Awt小试_第1张图片Awt小试_第2张图片Awt小试_第3张图片Awt小试_第4张图片Awt小试_第5张图片


Awt小试_第6张图片Awt小试_第7张图片Awt小试_第8张图片Awt小试_第9张图片Awt小试_第10张图片import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;


public class Text_BoxLayout extends JFrame{
	Box box1,box2,Box1;
	Text_BoxLayout()
	{
			box1=Box.createHorizontalBox();//水平盒式布局,组件初始化
			box1.add(new Label("name"));
			box1.add(Box.createHorizontalStrut(12));//水平距离
			box1.add(new TextField(12));
			box2=Box.createHorizontalBox();
			box2.add(new Label("sex"));
			box2.add(Box.createHorizontalStrut(12));
			box2.add(new TextField(12));
			Box1=Box.createVerticalBox();
			Box1.add(box1);
			Box1.add(Box.createVerticalStrut(12));
			Box1.add(box2);
			this.addWindowListener(new WindowAdapter()
			{

				@Override
				public void windowClosing(WindowEvent arg0) {
					// TODO Auto-generated method stub
					super.windowClosing(arg0);
					System.exit(0);
				}
				
			});
			this.setLayout(new FlowLayout());
			this.setBounds(100, 100, 200, 200);
			add(Box1);
			this.setVisible(true);
			this.validate();
			
	}

}


 


 

你可能感兴趣的:(String,Class,import,button,BT)