完成以下界面
代码如下:
import javax.swing.*;
import java.awt.*;
public class BasicComponentDemo {
Frame frame=new Frame("测试基本组件");
// 文本域
TextArea ta=new TextArea(5,10);
// 四个选择
Choice colorchoice =new Choice();
CheckboxGroup cbg=new CheckboxGroup();
Checkbox male=new Checkbox("男",true );
Checkbox female=new Checkbox("女",false);
Checkbox isMarried =new Checkbox("是否已婚");
//输入框 和按钮
TextField tf=new TextField(20);
Button bt=new Button("确认");
// 列表
List lt =new List(5);
public void init(){
//组装界面
//组装输入框和按钮
Box hbox_tf_bt=Box.createHorizontalBox();
hbox_tf_bt.add(tf);
hbox_tf_bt.add(bt);
frame.add(hbox_tf_bt,BorderLayout.SOUTH);
//组装选择部分
Box hbox_choice=Box.createHorizontalBox();
colorchoice.add("红色");
colorchoice.add("蓝色");
colorchoice.add("绿色");
hbox_choice.add(colorchoice);
hbox_choice.add(male);
hbox_choice.add(female);
hbox_choice.add(isMarried);
//组装文本域与选择部分
Box vbox_ta_choice=Box.createVerticalBox();
vbox_ta_choice.add(ta);
vbox_ta_choice.add(hbox_choice);
//组装文本域,选择部分及列表
Box hbox_ta_choice_lt =Box.createHorizontalBox();
hbox_ta_choice_lt.add(vbox_ta_choice);
hbox_ta_choice_lt.add(lt);
frame.add(hbox_ta_choice_lt);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
new BasicComponentDemo().init();
}
}