Choice下拉菜单
地址的下拉选项表,第一个Choice是省份第二个Choice是市区;选择省份的时候第二个会出现对应的市区
所有地区只能一个个对应,还是有现成的API?
一个个写全国那么多个地区,很多网站上都有这种地址选择项,是怎么做的啊,求大牛指教
Java API Choice?下拉列表
clientAdress2Choice.addItem(" ");
String[] clientAdress1 = {"请选择","江苏","浙江","湖南","安徽","四川","云南"};
for(int i = 0;i < 6;i++)
{
clientAdress1Choice.addItem(clientAdress1[i]);
}
clientAdress1Choice.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if(e.getItem().equals("江苏")){
clientAdress2Choice.removeAll();
String[] clientAdress2 = {"南京","常州","无锡","南通","苏州","徐州","扬州","镇江"};
for(int i = 0; i < 8;i++)
{
clientAdress2Choice.addItem(clientAdress2[i]);
}
}
if(e.getItem().equals("浙江")){
clientAdress2Choice.removeAll();
String[] clientAdress2 = {"杭州","嘉兴","湖州","温州"};
for(int i = 0; i < 4;i++)
{
clientAdress2Choice.addItem(clientAdress2[i]);
}
}
}
});