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

📄 extraguidemo2.java

📁 JAVA程序设计课程中各章节的程序实例。
💻 JAVA
字号:
/**
*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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -