Java SE (1)之 JFrame 组件 FlowLayout 布局

package com.sunzhiyan;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Demo_1 extends JFrame{

	/**
	 * @param args
	 */
	JButton button1,button2,button3;
	public static void main(String[] args) {
		// TODO Auto-generated method stub 
		Demo_1 demo = new Demo_1("hellow");
		
	       
	}
	public Demo_1(String name){
	    JButton button1 = new JButton("123"); 
	    JButton button2 = new JButton("456"); 
	    JButton button3 = new JButton("789"); 
	    this.add(button1);
	    this.add(button2);
	    this.add(button3);
            //启动流式布局,并且左浮动
	    this.setLayout(new FlowLayout(FlowLayout.LEFT));
	    
		this.setTitle(name);
		this.setSize(400,400);
		this.setLocation(100,100);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//this.setLayout(null);
		//this.setResizable(false);
		//this.setEnabled(true);
	    this.setVisible(true);    
	}

}

查JDK手册,可知 JButton

java.lang.Object
继承者
java.awt.Component 
继承者
java.awt.Container 
继承者
javax.swing.JComponent 
继承者
javax.swing.AbstractButton 
继承者
javax.swing.JButton
内部是这样的一个多继承的方式,因此底层的同时也能够使用上 层的方法和属性
原文地址:https://www.cnblogs.com/sunxun/p/3833042.html