FlowLayout

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.tsp2c.gui.event;

import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author Administrator
 */
public class FlowLayoutTest {
    public static void main(String args[]){
        FlowFrame ff = new FlowFrame();
        ff.setVisible(true);
    }

}


class FlowFrame extends JFrame{
    public FlowFrame(){
        setSize(400,300);
        setTitle("流佈局顯示");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //添加panel
        FlowPanel fp = new FlowPanel();
        add(fp);


    }
}

class FlowPanel extends JPanel{
    public FlowPanel(){
        //邊框佈局
        BorderLayout b1 = new BorderLayout();
        setLayout(b1);

        JButton btn1 = new JButton("土豆");
        JButton btn2 = new JButton("地瓜");
        JButton btn3 = new JButton("白薯");
        JButton btn4 = new JButton("紅薯");
        JButton btn5 = new JButton("山藥");


        add(btn1,BorderLayout.NORTH);
        add(btn2,BorderLayout.WEST);
        add(btn3,BorderLayout.EAST);
        add(btn4,BorderLayout.SOUTH);
        add(btn5,BorderLayout.CENTER);

    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章