写一个楼房管理的模块 现在要实现一个二级联动菜单创建了两个Comobox组件,第一个组件item内容为 房屋编号,第二个组件Item内容为房间编号要求第一个Comobox组件内的Item由数据库里查询出,第二个Comobox以第一个Comobox组件选择的的Item为关键字查询出数据,请教高手如何实现!尽量详细,谢谢!!!!
解决方案 »
- windwos下加载log4j.properties必须要把所在路径地址写在classpath最前面的问题
- 很有挑战性 看你行不行
- java 多态初始化问题
- 奇怪的java.lang.NoClassDefFoundError 错误
- DriverManager问题的jdbc
- 新年快乐----送分の三
- 如何JAVA开发中实现信息配置
- 我用eclipse怎么那么不顺利呀,连helloworld都编译不过?
- 北京学Java的培训班,是中软的好, 还是北大的好?
- Where can I find free Preference Book about JBuilder?
- JSP中一个很郁闷的问题,请高手进来指点
- Java相关的书集问题???
private JComboBox jComboBox1 = new JComboBox();
private JComboBox jComboBox2 = new JComboBox();
private JLabel Label1 = new JLabel();
private JLabel jLabel2 = new JLabel(); private Map _map = new HashMap();
public Frame1() {
try {
jbInit();
init();
} catch (Exception ex) {
ex.printStackTrace();
}
} private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jComboBox1.setBounds(new Rectangle(99, 31, 113, 30));
jLabel2.setToolTipText("");
this.getContentPane().add(jComboBox1);
jLabel2.setText("房间编号");
jLabel2.setBounds(new Rectangle(16, 100, 69, 29));
Label1.setText("房屋编号:");
Label1.setBounds(new Rectangle(21, 33, 71, 29));
this.getContentPane().add(Label1);
this.getContentPane().add(jLabel2);
this.getContentPane().add(jComboBox2);
jComboBox2.setBounds(new Rectangle(99, 95, 115, 32));
jComboBox1.addItemListener(new ItemHandler());
this.setSize(500,500);
}
private void init() {
initMap();
Iterator it = _map.keySet().iterator();
while(it.hasNext()) {
String key = (String) it.next();
jComboBox1.addItem(key);
}
} private void initMap() {
List list = new ArrayList();
list.add("01");
list.add("02");
list.add("03");
_map.put("No 1", list);
list = new ArrayList();
list.add("04");
list.add("05");
list.add("06");
_map.put("No 2", list);
}
private class ItemHandler implements ItemListener {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
return;
}
Object object = e.getSource();
jComboBox2.removeAllItems();
if (object == jComboBox1) {
String key = (String) jComboBox1.getSelectedItem();
List list = (List)_map.get(key);
if(null != list && !list.isEmpty()) {
for(int i = 0 ; i < list.size(); i++) {
String value = (String)list.get(i);
jComboBox2.addItem(value);
}
}
}
}
}
}希望对你有帮助,这是我辛辛苦苦写的哦
根据你的需求改改就可以了。