test040.java

package pack02;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

public class test040 extends JFrame
{

public static void main(String[] args)
{
new test040();

}

public test040()
{
this.setTitle("习题");
this.setLayout(new GridLayout(3,1,5,5));
Container container1 = this.getContentPane();
String[] colors = new String[] {"红","绿","蓝"};
JComboBox<String> comboBox1 = new JComboBox<>(colors);
container1.add(comboBox1);

JCheckBox checkBox1 = new JCheckBox("男");
JCheckBox checkBox2 = new JCheckBox("女");
JPanel panel1 = new JPanel(new FlowLayout());
panel1.add(checkBox1);
panel1.add(checkBox2);
container1.add(panel1);

JButton button1 = new JButton("确定");
JButton button2 = new JButton("取消");
JPanel panel2 = new JPanel(new FlowLayout());
panel2.add(button1);
panel2.add(button2);
container1.add(panel2);

this.setSize(500,300);
this.setVisible(true);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

}
}