import javax
.swing
.*
;
import java
.awt
.*
;
class Window extends JFrame
{
JTextField textField
;
JTextArea textArea
;
JCheckBox checkBox1
, checkBox2
;
JRadioButton radioButton1
, radioButton2
;
ButtonGroup group
;
JComboBox
<String> comboBox
;
JButton button
;
JLabel label
;
JPasswordField passwordField
;
public Window(){};
public Window(String s
, int x
, int y
, int w
, int h
)
{
inits(s
);
setLocation(x
, y
);
setSize(w
, h
);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE
);
}
void inits(String s
)
{
setTitle(s
);
setLayout(new FlowLayout());
Container con
= this.getContentPane();
con
.setBackground(Color
.black
);
textField
= new JTextField(50);
add(textField
);
textArea
= new JTextArea(10,10);
add(textArea
);
comboBox
= new JComboBox<String
>();
comboBox
.addItem("c++");
comboBox
.addItem("java");
add(comboBox
);
checkBox1
= new JCheckBox("喜欢方帅");
checkBox2
= new JCheckBox("喜欢路强");
add(checkBox1
);
add(checkBox2
);
group
= new ButtonGroup();
radioButton1
= new JRadioButton("一般人");
radioButton2
= new JRadioButton("二般人");
group
.add(radioButton1
);
group
.add(radioButton2
);
add(radioButton1
);
add(radioButton2
);
button
= new JButton("点我");
button
.setForeground(Color
.red
);
add(button
);
label
= new JLabel("标签");
label
.setForeground(Color
.red
);
add(label
);
passwordField
= new JPasswordField(10);
add(passwordField
);
}
}
public class test
{
public static void main(String args
[])
{
Window win
= new Window("常用组件",100,100,450,260);
}
}
注意设置背景颜色那部分
转载请注明原文地址:https://blackberry.8miu.com/read-44479.html