📄 testgridbaglayout.java
字号:
/* * TestGridBagLayout.java * * Created on July 30, 2002, 11:35 AM */package com.samspublishing.jpp.ch13;import java.awt.*;import java.awt.event.*;/** * * @author Stephen Potts * @version */public class TestGridBagLayout extends Frame{ TextField tfFirst; TextField tfSecond; TextField tfThird; TextField tfForth; TextField tfFifth; GridBagConstraints gbc; Button saveButton; Label answerLabel; /** Creates new GridBagLayout */ public TestGridBagLayout() { Insets i = new Insets(0, 0, 0, 0); saveButton = new Button("Save"); answerLabel = new Label("Answer:"); tfFirst = new TextField("First"); tfSecond= new TextField("Second"); tfThird = new TextField("Third"); tfForth = new TextField("Forth"); tfFifth = new TextField("Fifth"); GridBagLayout gbl = new GridBagLayout(); setLayout(gbl); gbc = new GridBagConstraints(0,0,1,1,0.0,0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, i,0,0); gbl.setConstraints(answerLabel, gbc); gbc = new GridBagConstraints(1,0,1,1,0.0,0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, i,0,0); gbl.setConstraints(tfFirst, gbc); gbc = new GridBagConstraints(1,11,1,1,0.0,0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, i,0,0); gbl.setConstraints(tfSecond, gbc); gbc = new GridBagConstraints(1,8,1,1,0.0,0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, i,0,0); gbl.setConstraints(tfThird, gbc); gbc = new GridBagConstraints(2,0,1,1,0.0,0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, i,0,0); gbl.setConstraints(tfForth, gbc); gbc = new GridBagConstraints(2,1,1,1,0.0,0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, i,0,0); gbl.setConstraints(tfFifth, gbc); gbc = new GridBagConstraints(8,1,1,1,0.0,0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, i,0,0); gbl.setConstraints(saveButton, gbc); add(tfFirst); add(tfSecond); add(tfThird); add(tfForth); add(tfFifth); add(answerLabel); add(saveButton); addWindowListener(new WinCloser()); setTitle("Using a GridBagLayout"); setBounds( 100, 100, 300, 300); setVisible(true); } public static void main(String[] args) { TestGridBagLayout tgbl = new TestGridBagLayout(); } }class WinCloser extends WindowAdapter{ public void windowClosing(WindowEvent e) { System.exit(0); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -