如题 
比方textfield里面显示(2+3)*(3-1)
点击 “=” textfield显示 10

解决方案 »

  1.   


    // 计算乘除的方法
     public static ArrayList result1(ArrayList lt) throws MyException {
      for (int i = 0; i < lt.size(); i++) {
       if (lt.get(i).equals("*") || lt.get(i).equals("/")) {
        Object ob1 = lt.get(i - 1);
        Object ob2 = lt.get(i);
        Object ob3 = lt.get(i + 1);
        String result = CalculateMethod.mulAndDivi(ob1.toString(), ob2
          .toString(), ob3.toString());
        lt.set(i - 1, result);
        lt.remove(i);
        lt.remove(i);
        result1(lt);
        break;
       }
      }
      return lt;
     } // 计算加减的方法
     public static String result2(ArrayList lt) throws MyException {
      if (lt.size() > 1) {
       String result = CalculateMethod.mulAndDivi(lt.get(0).toString(), lt
         .get(1).toString(), lt.get(2).toString());
       lt.remove(0);
       lt.remove(0);
       lt.remove(0);
       lt.add(0, result);
       result2(lt);
      }
      return lt.get(0).toString();
     } // 取得最后结果的方法
     public static String getResult(String s) throws MyException {
      String str = CalculateMethod.getStr(s);
      ArrayList lt1 = CalculateMethod.subStr(str);
      ArrayList lt2 = CalculateMethod.result1(lt1);
      String lt3 = CalculateMethod.result2(lt2);
      count = 0;
      lt.clear();
      return lt3;
     }
    }
    //参考代码:http://www.javaeye.com/topic/251674