zoukankan      html  css  js  c++  java
  • Java基础知识:Java实现Map集合二级联动4

     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)); // 重新添加市/县列表的值

      }

      }

      效果如图:

  • 相关阅读:
    拓端数据tecdat|R语言多元逐步回归模型分析房价和葡萄酒价格:选择最合适的预测变量
    拓端tecdat|R语言文本挖掘NASA数据网络分析,tf-idf和主题建模
    拓端tecdat|R语言资产配置: 季度战术资产配置策略研究
    拓端tecdat|R语言HAR和HEAVY模型分析高频金融数据波动率
    拓端tecdat|自然语言处理NLP:情感分析疫情下的新闻数据
    拓端tecdat|R语言中的SOM(自组织映射神经网络)对NBA球员聚类分析
    拓端tecdat|R语言:逻辑回归ROC曲线对角线分析过程及结果
    拓端tecdat|bilibili视频流量数据潜望镜
    codeforces#510 Div2
    树链剖分
  • 原文地址:https://www.cnblogs.com/-zpy/p/5016277.html
Copyright © 2011-2022 走看看