做网站就找喇叭人,外贸人才网,网站建设如何自学,开贸易公司怎么起步我有两个类#xff0c;一个包含两个组合框的监听器类和一个监听两个组合框的监听器类。该软件是关于披萨的#xff0c;而组合框的选择是披萨类型和数量#xff0c;我会发布相关的代码。(gui class)private Listener listen new Listener();private JComboBox chooseItem n…我有两个类一个包含两个组合框的监听器类和一个监听两个组合框的监听器类。该软件是关于披萨的而组合框的选择是披萨类型和数量我会发布相关的代码。(gui class)private Listener listen new Listener();private JComboBox chooseItem new JComboBox();private JComboBox quantity new JComboBox();private String[] selection {Choose a Pizza,Margherita, Pepperoni, Four Seasons, Chips, Garlic Bread, Potato Wedges, Cocacola, Orange Juice, Lemonade};private String[] qSelection {0,1,2,3,4,5,6,7,8,9,10};private void comboBoxs() {choosePizza new JComboBox(selection);chooseItem.setSelectedIndex(0);panel.add(choosePizza);choosPizza.addActionListener(listener);quantity new JComboBox(qSelection);quantity.setSelectedIndex(0);panel.add(quantity);quantity.addActionListener(listener);}在监听器类中我被卡住了至今还没有找到解决方案。我必须使用ActionListener但我不确定我是如何区分这两个组合框的。(listener class)public void actionPerformed(ActionEvent event) {if (actionCommand.equals(Confirm)) {String q new String();String d new String();d description;q quantity;}else {JComboBox cbq (JComboBox)event.getSource();String itemNumber (String)cbq.getSelectedItem();getQuantity(itemNumber);JComboBox cb (JComboBox)event.getSource();String name (String)cb.getSelectedItem();getItemName(name);}}public String getItemName(String name) {description new String();description name;return name;}public String getQuantity(String itemNumber){quantity new String();quantity itemNumber;return itemNumber;}因此总结一下当我在两个JComboBox中选择值时我希望能够在“description”字符串中存储选定的chooseItem JComboBox项目并在“quantity”字符串中存储所选数量的JComboBox项目。目前chooseItem JComboBox所选项目显示为两个值并且数量完全不显示。 (实际上这与前面使用的最后一个盒子出现在描述字符串中并且数量指向空值时一样。)我在网上找到的所有例子都只涉及带有单个JComboBox的ActionListener我一直试图让它工作几个小时但没有运气我完全被卡住了。