gbcall.java
来自「JAVA程序设计课程中各章节的程序实例。」· Java 代码 · 共 59 行
JAVA
59 行
/**
*A simple program using components within a panel with GridBagLayout
*2004.12.4.
*/
import java.awt.*;
import java.awt.event.*;
public class GBCall extends Frame
{
Panel pTime = new Panel();
Panel pApp = new Panel();
TextField txTime9 = new TextField("09:00");
TextField txTime930 = new TextField("09:30");
TextField txApp = new TextField("Meeting ");
GridBagLayout gb1 = new GridBagLayout();
GridBagLayout gb2 = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
public static void main(String args[])
{
GBCall gbc = new GBCall();
gbc.setLayout(new FlowLayout());
}
public GBCall()
{
setLayout(gb1);
pTime.setLayout(gb2);
gbc.gridx = 0;
gbc.gridy = 0;
pTime.add(txTime9,gbc);
gbc.gridx = 0;
gbc.gridy = 1;
pTime.add(txTime930,gbc);
pTime.setBackground(Color.red);
//RE-using gbc for the main panel layout!!!
gbc.gridx = 0;
gbc.gridy = 0;
gbc.ipadx = 30;
add(pTime,gbc);
pApp.setLayout(gb2);
gbc.gridx = 0;
gbc.gridy = 1;
pApp.add(txApp,gbc);
gbc.gridx = 1;
gbc.gridy = 0;
gbc.ipadx = 100;
pApp.setBackground(Color.lightGray);
add(pApp,gbc);
setSize(300,300);
setVisible(true);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?