java2实用教程(例子代码)第4版第九章例9_3
Lt4_3.java
public clss Lt4_3
{
public static void main(String args[])
{
ComponentInWindor win = new ComponentInWindor();
win.setBounds(100,100,310,260);
win.setTitle("常用组件");
}
}
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 JLable("文本框:"));
text = new JTextField(10);
add(text);
add(new JLable("按钮:"));
button = new JButton("确定");
add(button);
add(new JLable("选择框:"));
checkBox1 = new JCheckBox("喜欢音乐");
checkBox2 = new JCheckBox("喜欢旅游");