⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 j_gridbaglayout.java.bak

📁 一个十分好的java基础学习的课件
💻 BAK
字号:
// ////////////////////////////////////////////////////////
// 
// J_GridBagLayout.java
// 
// Created by Jun-Hai Yong,    on XX xx, xxxx (Date)
// ////////////////////////////////////////////////////////
// Readme:
//      Example of GridBagLayout.
// ////////////////////////////////////////////////////////
// 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_GridBagLayout
{
    public static void mb_makeButton( Container cp, String name, 
                                      GridBagLayout gridbag, GridBagConstraints c )
    {
        Button b = new Button(name);
        gridbag.setConstraints(b, c);
        cp.add(b);
    } // End of method: mb_makeButton

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

        Container container = app.getContentPane( );
        GridBagLayout gridbag = new GridBagLayout( );
        GridBagConstraints c = new GridBagConstraints( );
        container.setLayout(gridbag);
        
        c.fill = GridBagConstraints.BOTH;
        c.weightx = 1.0;
        mb_makeButton(container, "Button1", gridbag, c);
        mb_makeButton(container, "Button2", gridbag, c);
        mb_makeButton(container, "Button3", gridbag, c);
        
        c.gridwidth = GridBagConstraints.REMAINDER; //end row
        mb_makeButton(container, "Button4", gridbag, c);
        
        c.gridwidth = GridBagConstraints.RELATIVE;       //next-to-last in row
        mb_makeButton(container, "Button5", gridbag, c); //another row

        c.gridwidth = GridBagConstraints.REMAINDER;  //end row
        mb_makeButton(container, "Button6", gridbag, c);

        c.gridwidth = 1;	   	   //reset to the default
        c.gridheight = 2;
        c.weighty = 1.0;
        mb_makeButton(container, "Button7", gridbag, c);
        
        c.weighty = 0.0;		   //reset to the default
        c.gridwidth = GridBagConstraints.REMAINDER; //end row
        c.gridheight = 1;		   //reset to the default
        mb_makeButton(container, "Button8", gridbag, c);
        mb_makeButton(container, "Button9", gridbag, c);

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

} // End of class: J_GridBagLayout

⌨️ 快捷键说明

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