常用组件

import java.awt.FlowLayout;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class ComponentInWindow extends JFrame {
    JTextField text;
    JButton button;
    JCheckBox checkBox1,checkBox2,checkBox3;
    JRadioButton radio1,radio2;
    ButtonGroup group;
    JComboBox<String> comBox;
    JTextArea area;
    public ComponentInWindow(){
        setVisible(true);
        init();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    private void init() {
        // TODO Auto-generated method stub
        setLayout(new FlowLayout());   // 垂直布局
        JLabel label = new JLabel("文本框"); 
        add(label);                 //  添加标签
        text = new JTextField(10);  
        add(text);                    //添加文本框
        button = new JButton("确定");
        add(button);                   
        checkBox1 = new JCheckBox("喜欢音乐"); // 复选框
        checkBox2 = new JCheckBox("喜欢旅游");
        checkBox3 = new JCheckBox("喜欢篮球");
        add(checkBox1);
        add(checkBox2);
        add(checkBox3);
        group  = new ButtonGroup();          //单选组
        radio1 = new JRadioButton("帅哥");   // 单选按钮
        radio2 = new JRadioButton("美女");
        group.add(radio1);
        group.add(radio2);
        add(radio1);
        add(radio2);
        comBox = new JComboBox<String>();
        comBox.addItem("音乐天地");
        comBox.addItem("武术天地");
        comBox.addItem("象棋乐园");
        add(comBox);
        area = new JTextArea(6,12);
        add(new JScrollPane(area)); //  显示 文本区
    }

}

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值