JComboBox数据库连接 “省市县”三级联动显示

iFrmPrProvice = new JComboBox();

		iFrmPrProvice.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Iterator ProvinceIt = dao.queryProvince().iterator();
				while (ProvinceIt.hasNext()) {
					PROVINCE p = (PROVINCE) ProvinceIt.next();
					iFrmPrProvice.addItem(p.getPROVINCENAME());
				}
			}
		});
		iFrmPrProvice.addItem("选择省");
		iFrmPrProvice.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				if (iFrmPrCity != null) {
					iFrmPrCity.removeAllItems();
				}
				if (iFrmPrCountry != null) {
					iFrmPrCountry.removeAllItems();
				}
				provinceName = iFrmPrProvice.getSelectedItem().toString();
				PROVINCE pr = (PROVINCE) dao.queryProvinceByName(provinceName);
					Set c = pr.getCity();
					for (Iterator it = c.iterator(); it.hasNext();) {
						CITY city = (CITY) it.next();
						iFrmPrCity.addItem(city.getCITYNAME());
					}
                         }
		});

		getContentPane().add(iFrmPrProvice, "8, 2, fill, fill");

		iFrmPrCity = new JComboBox();
		iFrmPrCity.addItem("选择市");
		iFrmPrCity.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				if (e.getStateChange() == ItemEvent.SELECTED) {
					if (iFrmPrCountry != null) {
						iFrmPrCountry.removeAllItems();
					}
					cityName = iFrmPrCity.getSelectedItem().toString();
					CITY c = (CITY) dao.queryCityByName(cityName);
					Set country = c.getCountry();
					for (Iterator it = country.iterator(); it.hasNext();) {
						COUNTRY co = (COUNTRY) it.next();
						iFrmPrCountry.addItem(co.getCOUNTRYNAME());
					}
				}
				return;
			}
		});


		getContentPane().add(iFrmPrCity, "10, 2, fill, fill");

		iFrmPrCountry = new JComboBox();

		iFrmPrCountry.addItem("选择县");
		getContentPane().add(iFrmPrCountry, "12, 2, fill, fill");
		{
			JScrollPane scrollPane = new JScrollPane();
			getContentPane().add(scrollPane, "2, 4, 11, 1, fill, fill");
			iFrmPrdescription = new JTextArea();
			scrollPane.setViewportView(iFrmPrdescription);
			iFrmPrdescription.setFont(new Font("仿宋_GB2312", Font.PLAIN, 20));
			iFrmPrdescription.setLineWrap(true);
		}

	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值