您的位置:首页 > 产品设计 > UI/UE

GUI 文本框、复选框、单选框、下拉列表

2018-02-06 11:59 1081 查看
ComponentInWindow.java文件:

import java.awt.*;

import javax.swing.*;

public class ComponentInWindow extends JFrame {
JTextField text;
JButton button;
JCheckBox checkBox1,checkBox2,checkBox3;
JRadioButton radio1,radio2;
ButtonGroup group;
JComboBox comBox;
JTextArea area;
public ComponentInWindow(){
init();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
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();//下拉列表
comBox.addItem("音乐天地");
comBox.addItem("武术海洋");
comBox.addItem("象棋乐园");
add(comBox);
area = new JTextArea(6,12);
add(new JScrollPane(area));
}

}
Example3.java文件:
public class Example3 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ComponentInWindow win = new ComponentInWindow();
win.setBounds(100,100,300,260);
win.setTitle("常用组件");
}

}
效果图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息