【JAVA】常用组件
本文最后更新于 1551 天前,其中的信息可能已经有所发展或是发生改变。

1.创建ComponentInWindow类

[sourcecode language=”java” title=”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() {
setLayout(new FlowLayout());
add(new JLabel("文本框:"));
text = new JTextField(10);
add(text);
add(new JLabel("按钮:"));
button = new JButton("确定");
add(button);
add(new JLabel("选择框:"));
checkBox1 = new JCheckBox("喜欢音乐");
checkBox2 = new JCheckBox("喜欢旅游");
checkBox3 = new JCheckBox("喜欢篮球");
add(checkBox1);
add(checkBox2);
add(checkBox3);
add(new JLabel("单选按钮:"));
group = new ButtonGroup();
radio1 = new JRadioButton("男");
radio2 = new JRadioButton("女");
group.add(radio1);
group.add(radio2);
add(radio1);
add(radio2);
add(new JLabel("下拉列表:"));
comBox = new JComboBox();
comBox.addItem("音乐天地");
comBox.addItem("武术天地");
comBox.addItem("象棋乐园");
add(comBox);
add(new JLabel("文本区:"));
area = new JTextArea(6,12);
add(new JScrollPane(area));
}
}
[/sourcecode]

2.创建主类

[sourcecode language=”java” title=”Example9_3.java”]
public class Example9_3 {

public static void main(String[] args) {
ComponentInWindow win = new ComponentInWindow();
win.setBounds(100,100,310,260);
win.setTitle("常用组件");

}

}
[/sourcecode]

运行效果:

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇