testgridlayout.java
来自「Java the UML Way 书中所有源码」· Java 代码 · 共 35 行
JAVA
35 行
/*
* TestGridLayout.java E.L. 2001-08-18
*
*/
import java.awt.*;
import javax.swing.*;
public class TestGridLayout extends JApplet {
private JTextField name = new JTextField(15);
private JTextField address = new JTextField(15);
private JTextField phone = new JTextField(15);
private JTextField eMail = new JTextField(15);
public void init() {
Container guiContainer = getContentPane();
/*
* The GridLayout constructor takes the following arguments:
* No. of rows, no. of columns, horizontal and vertical gap between the cells.
*/
guiContainer.setLayout(new GridLayout(4, 2, 5, 5));
JLabel label = new JLabel("Name:", JLabel.RIGHT);
guiContainer.add(label);
guiContainer.add(name);
label = new JLabel("Address:", JLabel.RIGHT);
guiContainer.add(label);
guiContainer.add(address);
label = new JLabel("Phone:", JLabel.RIGHT);
guiContainer.add(label);
guiContainer.add(phone);
label = new JLabel("E-mail:", JLabel.RIGHT);
guiContainer.add(label);
guiContainer.add(eMail);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?