importjavax.swing.*;importjava.awt.*;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;classTestextendsJFrame{JCheckBoxcheckbox;//复选框JComboBoxcombob...
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class Test extends JFrame{
JCheckBox checkbox;// 复选框
JComboBox combobox;// 下拉菜单
public Test() {
setSize(500, 500);
this.setLocation(300, 300);
setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
checkbox = new JCheckBox("控制地区显示", true);
Container c = this.getContentPane();
c.setLayout(null);
c.add(checkbox);
checkbox.setLocation(100, 0);
checkbox.setSize(120, 20);
combobox = new JComboBox();
c.add(combobox);
combobox.setEnabled(false);
combobox.addItem("北京");
combobox.addItem("上海");
combobox.addItem("深圳");
combobox.addItem("平顶山");
combobox.setLocation(300, 0);
combobox.setSize(100, 20);
}
public static void main(String args[]) {
Test e = new Test();
}
}
我想用复选框控制下拉菜单是不是可见,,,
怎么弄??
这样的,如果复选框让选中了,
combobox.setEnabled(true);//显示
这样的,如果复选框没有让选中了,
combobox.setEnabled(flase);//不显示
如何实现这样的监听???
展开