learning java AWT 常见组件

import javax.swing.*;
import java.awt.*;

public class CommonComponent {
    Frame f = new Frame("test");
    Button ok = new Button("confirmed");
    CheckboxGroup cbg = new CheckboxGroup();
    Checkbox male = new Checkbox("man", cbg, true);
    Checkbox female = new Checkbox("woman", cbg,false);
    Checkbox married = new Checkbox("married?", false);

    Choice colorChooser = new Choice();

    List colorList = new List(6,true);

    TextArea ta = new TextArea(5,20);

    TextField name = new TextField(50);
    public void init(){
        colorChooser.add("red");
        colorChooser.add("blue");
        colorChooser.add("green");

        colorList.add("red");
        colorList.add("blue");
        colorList.add("green");

        var botton = new Panel();
        botton.add(name);
        botton.add(ok);
        f.add(botton, BorderLayout.SOUTH);

        var checkPannel  = new Panel();
        checkPannel.add(colorChooser);
        checkPannel.add(male);
        checkPannel.add(female);
        checkPannel.add(married);

        var topLeft = Box.createVerticalBox();
        topLeft.add(ta);
        topLeft.add(checkPannel);

        //f.add(topLeft);

        var top = Box.createHorizontalBox();
        top.add(topLeft);
        top.add(colorList);

        f.add(top);
        f.pack();
        f.setVisible(true);
    }

    public static void main(String[] args) {
        new CommonComponent().init();
    }

}

output:

posted @ 2019-07-30 16:38  嵌入式实操  阅读(286)  评论(0编辑  收藏  举报