![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
怎么把checkbox和combobox结合
package ww;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Sx extends Frame implements ItemListener{
/**
* @param args
*/
Checkbox checkbox;
Choice choice;
public Sx() {
this.setBounds(100, 100, 400, 300);
this.setLayout(new FlowLayout());
checkbox = new Checkbox("勾选");
choice = new Choice();
for (int i = 0; i < 6; i++) {
choice.add(i + "");
}
// choice.setVisible(false);
this.add(checkbox);
this.add(choice);
choice.setEnabled(false);
checkbox.addItemListener(this);
this.setVisible(true);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Sx();
}
@Override
public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
if(checkbox.getState())
{
choice.setEnabled(true);
}
else if(!checkbox.getState())
{
choice.setEnabled(false);
}
}
}