extraguidemo2.java
来自「JAVA程序设计课程中各章节的程序实例。」· Java 代码 · 共 71 行
JAVA
71 行
/**
*Another GUI demonstration program
*2005.1.11 xhcprince
*/
import java.awt.*;
public class extraGUIDemo2
{
public static void main(String args[])
{
Frame f = new Frame();
f.setSize(300,200);
GridBagLayout gb = new GridBagLayout();
f.setLayout(gb);
GridBagConstraints gs = new GridBagConstraints();
gs.fill = GridBagConstraints.BOTH;
Button b1 = new Button("Button 1");
Button b2 = new Button("Button 2");
TextField tf = new TextField("Grid Bag example");
Label L = new Label("This just displays some text");
TextArea ta = new TextArea(6,11);
Scrollbar sb = new Scrollbar();
gs = new GridBagConstraints(); //pay attention,you have to construct again!
gs.gridx = gs.gridy = 0;
gs.anchor = GridBagConstraints.SOUTH;
gs.weightx = gs.weighty = 1.0;
f.add(L,gs);
gs = new GridBagConstraints(); //pay attention,you have to construct again!
gs.gridx = 0;
gs.fill = GridBagConstraints.BOTH;
gs.gridwidth = 2;
gs.gridheight = 3;
gs.weightx = 1.0;
gs.weighty = 3.0;
f.add(ta,gs);
gs = new GridBagConstraints();
gs.gridy = 0;
gs.fill = GridBagConstraints.BOTH;
gs.anchor = GridBagConstraints.NORTH;
gs.weightx = gs.weighty = 1.0;
f.add(tf,gs);
gs = new GridBagConstraints();
gs.gridy = 0;
gs.weightx = gs.weighty = 1.0;
f.add(b1,gs);
gs = new GridBagConstraints();
gs.gridy = 2;
gs.anchor = GridBagConstraints.NORTHEAST;
gs.weightx = gs.weighty = 1.0;
f.add(b2,gs);
gs = new GridBagConstraints();
gs.gridy = 0;
gs.gridheight = GridBagConstraints.REMAINDER;
gs.fill = GridBagConstraints.VERTICAL;
gs.anchor = GridBagConstraints.EAST;
gs.weightx = gs.weighty = 1.0;
f.add(sb,gs);
f.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?