?? commoncomponent.java
字號:
import java.awt.*;
import javax.swing.*;
/**
* Description:
* <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class CommonComponent
{
Frame f = new Frame("測試");
//定義一個按鈕
Button ok = new Button("確認");
CheckboxGroup cbg = new CheckboxGroup();
//定義一個單選框(處于cbg一組),初始處于被選中狀態
Checkbox male = new Checkbox("男" , cbg , true);
//定義一個單選框(處于cbg一組),初始處于沒有選中狀態
Checkbox female = new Checkbox("女" , cbg , false);
//定義一個復選框,初始處于沒有選中狀態
Checkbox married = new Checkbox("是否已婚?" , false);
//定義一個下拉選擇框
Choice colorChooser = new Choice();
//定義一個列表選擇框
List colorList = new List(6, true);
//定義一個5行、20列的多行文本域
TextArea ta = new TextArea(5, 20);
//定義一個50列的單行文本域
TextField name = new TextField(50);
public void init()
{
colorChooser.add("紅色");
colorChooser.add("綠色");
colorChooser.add("藍色");
colorList.add("紅色");
colorList.add("綠色");
colorList.add("藍色");
//創建一個裝載了文本框、按鈕的Panel
Panel bottom = new Panel();
bottom.add(name);
bottom.add(ok);
f.add(bottom , BorderLayout.SOUTH);
//創建一個裝載了下拉選擇框、三個Checkbox的Panel
Panel checkPanel = new Panel();
checkPanel.add(colorChooser);
checkPanel.add(male);
checkPanel.add(female);
checkPanel.add(married);
//創建一個垂直排列組件的Box,盛裝多行文本域、Panel
Box topLeft = Box.createVerticalBox();
topLeft.add(ta);
topLeft.add(checkPanel);
//創建一個垂直排列組件的Box,盛裝topLeft、colorList
Box top = Box.createHorizontalBox();
top.add(topLeft);
top.add(colorList);
//將top Box容器添加到窗口的中間
f.add(top);
f.pack();
f.setVisible(true);
}
public static void main(String[] args)
{
new CommonComponent().init();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -