j_gridlayout.java.bak

来自「一个十分好的java基础学习的课件」· BAK 代码 · 共 45 行

BAK
45
字号
// ////////////////////////////////////////////////////////
// 
// J_GridLayout.java
// 
// Created by Jun-Hai Yong,    on XX xx, xxxx (Date)
// ////////////////////////////////////////////////////////
// Readme:
//      Example of GridLayout.
// ////////////////////////////////////////////////////////
// Using this example, please explicitly refer to the book:
//     Jun-Hai Yong. Programming in Java. 
//     Beijing: Tsinghua University Press, 2004.
// 使用本例子,请注明引用:
//     雍俊海. Java 程序设计. 北京: 清华大学出版社, 2004.
// Please note that the author and publisher make no 
// warranty of any kind on the examples provided.
// ////////////////////////////////////////////////////////

import java.awt.*;
import javax.swing.*;

public class J_GridLayout
{
    public static void main( String args[] )
    { 
        JFrame app = new JFrame("GridLayout");

        Container container = app.getContentPane( );
        container.setLayout( new GridLayout(2, 3) ); // grids: 2 rows by 3 columns

        JButton [] b= new JButton[5];
        for (int i= 0; i< 5; i++)
        {
            String s= "Button " + (i+1);
            b[i]= new JButton(s);
            container.add( b[i] );
        } // End of loop: for

        app.setSize( 300, 100 );
        app.setVisible( true );
        app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
    } // End of method: main

} // End of class: J_GridLayout

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?