您好,欢迎光临本网站![请登录][注册会员]  
文件名称: JComboBoxModel三级联动
  所属分类: Java
  开发工具:
  文件大小: 6kb
  下载次数: 0
  上传时间: 2010-07-28
  提 供 者: maxz****
 详细说明: import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; public class ComboBoxDemo extends JFrame { private DefaultComboBoxModel model = new DefaultComboBoxModel(); private DefaultComboBoxModel model1 = new DefaultComboBoxModel(); private DefaultComboBoxModel model2 = new DefaultComboBoxModel(); private JComboBox firstComboBox; private JComboBox secondComboBox; private JComboBox t hirdComboBox; private String[] first = { "001", "002", "003" }; private String[] second_first = { "00101", "00102", "00103" }; private String[] second_second = { "00201", "00202", "00203" }; private String[] second_third = { "00301", "00302", "00303" }; private String[] third_first_first = { "0010101", "0010102", "0010103" }; private String[] third_second_first = { "0010201", "0010202", "0010203" }; private String[] third_third_first = { "0010301", "0010302", "0010303" }; private String[] third_second_second = { "0020101", "0020102", "0020103" }; private String[] third_first_second = { "0020201", "0020202", "0020203" }; private String[] third_third_second = { "0020301", "0020302", "0020303" }; private String[] third_first_third = { "0030101", "0030102", "0030103" }; private String[] third_second_third = { "0030201", "0030202", "0030203" }; private String[] third_third_third = { "0030301", "0030302", "0030303" }; public ComboBoxDemo() { setTitle("ComboBoxTest"); setSize(300, 200); setDefaultCloseOperation(EXIT_ON_CLOSE); for (int i = 0, n = first.length; i < n; i++) { model.addElement(first[i]); } firstComboBox = new JComboBox(model); firstComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JComboBox source = (JComboBox) evt.getSource(); String item = (String) source.getSelectedItem(); try { if (item.equals("001")) { model1.removeAllElements(); for (int i = 0, n = second_first.length; i < n; i++) { model1.addElement(second_first[i]); } model2.removeAllElements(); for (int i = 0, n = third_first_first.length; i < n; i++) { model2.addElement(third_first_first[i]); } } else if (item.equals("002")) { model1.removeAllElements(); for (int i = 0, n = second_second.length; i < n; i++) { model1.addElement(second_second[i]); } model2.removeAllElements(); for (int i = 0, n = third_second_second.length; i < n; i++) { model2.addElement(third_second_second[i]); } } else if (item.equals("003")) { model1.removeAllElements(); for (int i = 0, n = second_third.length; i < n; i++) { model1.addElement(second_third[i]); } model2.removeAllElements(); for (int i = 0, n = third_first_third.length; i < n; i++) { model2.addElement(third_first_third[i]); } } else { System.out.println("error!"); } } catch (Exception e) { } } }); for (int i = 0, n = second_first.length; i < n; i++) { model1.addElement(second_first[i]); } secondComboBox = new JComboBox(model1); secondComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JComboBox source = (JComboBox) evt.getSource(); String item1 = (String) source.getSelectedItem(); try { if (item1.equals("00101")) { model2.removeAllElements(); for (int i = 0, n = third_first_first.length; i < n; i++) { model2.addElement(third_first_first[i]); } } else if (item1.equals("00102")) { model2.removeAllElements(); for (int i = 0, n = third_second_first.length; i < n; i++) { model2.addElement(third_second_first[i]); } } else if (item1.equals("00103")) { model2.removeAllElements(); for (int i = 0, n = third_third_first.length; i < n; i++) { model2.addElement(third_third_first[i]); } } else if (item1.equals("00201")) { model2.removeAllElements(); for (int i = 0, n = third_second_second.length; i < n; i++) { model2.addElement(third_second_second[i]); } } else if (item1.equals("00202")) { model2.removeAllElements(); for (int i = 0, n = third_first_second.length; i < n; i++) { model2.addElement(third_first_second[i]); } } else if (item1.equals("00203")) { model2.removeAllElements(); for (int i = 0, n = third_third_second.length; i < n; i++) { model2.addElement(third_third_second[i]); } } else if (item1.equals("00301")) { model2.removeAllElements(); for (int i = 0, n = third_first_third.length; i < n; i++) { model2.addElement(third_first_third[i]); } } else if (item1.equals("00302")) { model2.removeAllElements(); for (int i = 0, n = third_second_third.length; i < n; i++) { model2.addElement(third_second_third[i]); } } else if (item1.equals("00303")) { model2.removeAllElements(); for (int i = 0, n = third_third_third.length; i < n; i++) { model2.addElement(third_third_third[i]); } } } catch (Exception e) { System.out.println(); } } }); for (int i = 0, n = third_first_first.length; i < n; i++) { model2.addElement(third_first_first[i]); } thirdComboBox = new JComboBox(model2); JPanel p = new JPanel(); p.add(firstComboBox); p.add(secondComboBox); p.add(thirdComboBox); getContentPane().add(p, "North"); setLocation(400, 200); setVisible(true); } public static void main(String[] args) { new ComboBoxDemo(); } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: JComboBoxModel三级联动
 输入关键字,在本站1000多万海量源码库中尽情搜索: