jComboBox1.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jComboBox1ActionPerformed(evt);

          if (jComboBox1.getSelectedItem().equals(" "))
            {
                rlsum = addElement(sumthing );
            }
         if (jComboBox1.getSelectedItem().equals("S"))
            {
                rlsum = addElement(sumthing/64 );
            }
         if (jComboBox1.getSelectedItem().equals("Z"))
            {
                rlsum = addElement(sumthing/220 );
            }
       }

        private Object addElement(double i) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });


我想知道如何在不每次都被抛出的情况下读取变量求和...我在Jcombo框中添加了带有匹配标签的动作侦听器,但是每次选择一个标签时,它都指向抛出的代码。

最佳答案

您的问题出在下面的代码。您在UnsupportedException操作期间抛出addElement

private Object addElement(double i) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }


首先使用与您的应用程序需求相关的逻辑来实现addElement。

用下面的代码替换addElement(),以免引发异常

 private Object addElement(double i) {

            //put your business logic, add relevant exception handling for your requirement
            }

09-10 23:16