首页 技术 正文
技术 2022年11月17日
0 收藏 740 点赞 4,816 浏览 2688 个字

 comboBox.setModel(new DefaultComboBoxModel(getProvince())); // 添加省份信息

  final JLabel label = new JLabel();

  label.setText(“省/直辖市”);

  label.setBounds(155, 30, 66, 18);

  panel.add(label);

  final JLabel label_1 = new JLabel();

  label_1.setText(“市/县”);

  label_1.setBounds(375, 30, 37, 18);

  panel.add(label_1);

  final JLabel label_2 = new JLabel();

  label_2.setBounds(36, 43, 65, 18);

  backgroundPanel.add(label_2);

  label_2.setHorizontalAlignment(SwingConstants.RIGHT);

  label_2.setHorizontalTextPosition(SwingConstants.LEADING);

  label_2.setText(“姓 名:”);

  textField = new JTextField();

  textField.setBounds(113, 38, 154, 28);

  backgroundPanel.add(textField);

  final JLabel label_3 = new JLabel();

  label_3.setBounds(36, 84, 65, 18);

  backgroundPanel.add(label_3);

  label_3.setHorizontalAlignment(SwingConstants.RIGHT);

  label_3.setHorizontalTextPosition(SwingConstants.LEADING);

  label_3.setText(“性 别:”);

  comboBox_1 = new JComboBox();

  comboBox_1.setBounds(113, 81, 66, 25);

  backgroundPanel.add(comboBox_1);

  comboBox_1.setModel(new DefaultComboBoxModel(new String[] {“男”, “女”}));

  final JLabel label_4 = new JLabel();

  label_4.setBounds(36, 212, 65, 18);

  backgroundPanel.add(label_4);

  label_4.setHorizontalAlignment(SwingConstants.RIGHT);

  label_4.setHorizontalTextPosition(SwingConstants.LEADING);

  label_4.setText(“详细地址:”);

  textField_1 = new JTextField();

  textField_1.setBounds(113, 208, 367, 28);

  backgroundPanel.add(textField_1);

  final JLabel label_4_1 = new JLabel();

  label_4_1.setBounds(36, 252, 65, 18);

  backgroundPanel.add(label_4_1);

  label_4_1.setHorizontalTextPosition(SwingConstants.LEADING);

  label_4_1.setHorizontalAlignment(SwingConstants.RIGHT);

  label_4_1.setText(“E-mail:”);

  textField_3 = new JTextField();

  textField_3.setBounds(113, 248, 367, 27);

  backgroundPanel.add(textField_3);

  final JButton button = new JButton();

  button.setBounds(159, 289, 75, 28);

  backgroundPanel.add(button);

  button.setText(“保存”);

  final JButton button_1 = new JButton();

  button_1.setBounds(265, 289, 75, 28);

  backgroundPanel.add(button_1);

  button_1.setText(“重置”);

  //

  }

  /**

  * 获取省、直辖市,自治区

  *

  * @return

  */

  public Object[] getProvince() {

  Map map = CityMap.model;// 获取省份信息保存到Map中

  Set set = map.keySet(); // 获取Map集合中的键,并以Set集合返回

  Object[] province = set.toArray(); // 转换为数组

  return province; // 返回获取的省份信息

  }

  /**

  * 获取指定省对应的市/县

  *

  * @param selectProvince

  * @return

  */

  public String[] getCity(String selectProvince) {

  Map map = CityMap.model; // 获取省份信息保存到Map中

  String[] arrCity = map.get(selectProvince); // 获取指定键的值

  return arrCity; // 返回获取的市/县

  }

  private void itemChange() {

  String selectProvince = (String) comboBox.getSelectedItem();

  cityComboBox.removeAllItems(); // 清空市/县列表

  String[] arrCity = getCity(selectProvince); // 获取市/县

  cityComboBox.setModel(new DefaultComboBoxModel(arrCity)); // 重新添加市/县列表的值

  }

  }

  效果如图:

Java基础知识:Java实现Map集合二级联动4

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289