else{
                             FLAG2++;
                             OP3+=9/Math.pow(10,(double)FLAG2);
                             op=new Double(OP1+OP3);
                             result.setText(op.toString(op.doubleValue()));
                         }
                   }
                   else{
                         if(FLAG2<0){
                             OP2=10*OP2+9;
                             op=new Double(OP2);
                             result.setText(op.toString(op.doubleValue()));
                         }
                         else{
                             FLAG2++;
                             OP3+=9/Math.pow(10,(double)FLAG2);
                             op=new Double(OP2+OP3);
                             result.setText(op.toString(op.doubleValue()));
                         }
                   }
             } 
             if(e.getActionCommand()=="button4") { 
                   FLAG1=4; 
                   FLAG2=-1;
             }
             if(e.getActionCommand()=="button5") { 
                   if(FLAG1==0){
                         if(FLAG2<0){
                             OP1=10*OP1+4;
                             op=new Double(OP1);
                             result.setText(op.toString(op.doubleValue()));
                         }
                         else{
                             FLAG2++;
                             OP3+=4/Math.pow(10,(double)FLAG2);
                             op=new Double(OP1+OP3);
                             result.setText(op.toString(op.doubleValue()));
                         }
                   }
                   else{
                         if(FLAG2<0){
                             OP2=10*OP2+4;
                             op=new Double(OP2);
                             result.setText(op.toString(op.doubleValue()));
                         }
                         else{
                             FLAG2++;
                             OP3+=4/Math.pow(10,(double)FLAG2);
                             op=new Double(OP2+OP3);
                             result.setText(op.toString(op.doubleValue()));
                         }
                   }
             }               
             if(e.getActionCommand()=="button6") { 
                   if(FLAG1==0){
                         if(FLAG2<0){
                             OP1=10*OP1+5;
                             op=new Double(OP1);
                             result.setText(op.toString(op.doubleValue()));
                         }
                         else{
                             FLAG2++;
                             OP3+=5/Math.pow(10,(double)FLAG2);
                             op=new Double(OP1+OP3);
                             result.setText(op.toString(op.doubleValue()));
                         }
                   }
                   else{
                         if(FLAG2<0){
                             OP2=10*OP2+5;
                             op=new Double(OP2);
                             result.setText(op.toString(op.doubleValue()));
                         }
                         else{
                             FLAG2++;
                             OP3+=5/Math.pow(10,(double)FLAG2);
                             op=new Double(OP2+OP3);
                             result.setText(op.toString(op.doubleValue()));
                         }
                   }
             }   
             if(e.getActionCommand()=="button7") {
                   if(FLAG1==0){
                         if(FLAG2<0){
                             OP1=10*OP1+6;
                             op=new Double(OP1);
                             result.setText(op.toString(op.doubleValue()));
                         }
                         else{
                             FLAG2++;
                             OP3+=6/Math.pow(10,(double)FLAG2);
                             op=new Double(OP1+OP3);
                             result.setText(op.toString(op.doubleValue()));
                         }
                   }
                   else{
                         if(FLAG2<0){
                             OP2=10*OP2+6;
                             op=new Double(OP2);
                             result.setText(op.toString(op.doubleValue()));
                         }
                         else{
                             FLAG2++;
                             OP3+=6/Math.pow(10,(double)FLAG2);
                             op=new Double(OP2+OP3);
                             result.setText(op.toString(op.doubleValue()));
                         }
                   }
             }
             if(e.getActionCommand()=="button8") { 
                   FLAG1=8;
                   FLAG2=-1;
             }
             if(e.getActionCommand()=="button9") { 
                   if(FLAG1==0){
                         if(FLAG2<0){
                             OP1=10*OP1+1;
                              op=new Double(OP1);
                             result.setText(op.toString(op.doubleValue()));
                         }
                         else{
                             FLAG2++;
                             OP3+=1/Math.pow(10,(double)FLAG2);
                             op=new Double(OP1+OP3);
                             result.setText(op.toString(op.doubleValue()));
                         }
                   }
                   else{
                         if(FLAG2<0){
                             OP2=10*OP2+1;
                             op=new Double(OP2);
                             result.setText(op.toString(op.doubleValue()));
                         }
                         else{
                             FLAG2++;
                             OP3+=1/Math.pow(10,(double)FLAG2);
                             op=new Double(OP2+OP3);
                             result.setText(op.toString(op.doubleValue()));
                         }
                   }
             }
             if(e.getActionCommand()=="button10") { 
                   if(FLAG1==0){
                         if(FLAG2<0){
                             OP1=10*OP1+2;
                              op=new Double(OP1);
                             result.setText(op.toString(op.doubleValue()));
                         }
                         else{
                             FLAG2++;
                             OP3+=2/Math.pow(10,(double)FLAG2);
                             op=new Double(OP1+OP3);
                             result.setText(op.toString(op.doubleValue()));
                         }
                   }

解决方案 »

  1.   


                       else{
                             if(FLAG2<0){
                                 OP2=10*OP2+2;
                                 op=new Double(OP2);
                                 result.setText(op.toString(op.doubleValue()));
                             }
                             else{
                                 FLAG2++;
                                 OP3+=2/Math.pow(10,(double)FLAG2);
                                 op=new Double(OP2+OP3);
                                 result.setText(op.toString(op.doubleValue()));
                             }
                       }
                 }
                 if(e.getActionCommand()=="button11") { 
                       if(FLAG1==0){
                             if(FLAG2<0){
                                 OP1=10*OP1+3;
                                  op=new Double(OP1);
                                 result.setText(op.toString(op.doubleValue()));
                             }
                             else{
                                 FLAG2++;
                                 OP3+=3/Math.pow(10,(double)FLAG2);
                                 op=new Double(OP1+OP3);
                                 result.setText(op.toString(op.doubleValue()));
                             }
                       }
                       else{
                             if(FLAG2<0){
                                 OP2=10*OP2+3;
                                 op=new Double(OP2);
                                 result.setText(op.toString(op.doubleValue()));
                             }
                             else{
                                 FLAG2++;
                                 OP3+=3/Math.pow(10,(double)FLAG2);
                                 op=new Double(OP2+OP3);
                                 result.setText(op.toString(op.doubleValue()));
                             }
                       }
                 }
                 if(e.getActionCommand()=="button12") {
                       FLAG1=12;
                       FLAG2=-1;
                 }
                 if(e.getActionCommand()=="button13") { 
                       if(FLAG1==0){
                             if(FLAG2<0){
                                 OP1=10*OP1+0;
                                 op=new Double(OP1);
                                 result.setText(op.toString(op.doubleValue()));
                             }
                             else{
                                 FLAG2++;
                                 OP3+=0/Math.pow(10,(double)FLAG2);
                                 op=new Double(OP1+OP3);
                                 result.setText(op.toString(op.doubleValue()));
                             }
                       }
                       else{
                             if(FLAG2<0){
                                 OP2=10*OP2+0;
                                 op=new Double(OP2);
                                 result.setText(op.toString(op.doubleValue()));
                             }
                             else{
                                 FLAG2++;
                                 OP3+=0/Math.pow(10,(double)FLAG2);
                                 op=new Double(OP2+OP3);
                                 result.setText(op.toString(op.doubleValue()));
                             }
                       }
                 }
                 if(e.getActionCommand()=="button14") { 
                       if(FLAG1==0){
                             OP1=Math.PI;
                             op=new Double(OP1);
                             result.setText(op.toString(op.doubleValue()));
                       }
                       else{
                             OP2=Math.PI;
                             op=new Double(OP2);
                             result.setText(op.toString(op.doubleValue()));
                       }      
                  }       
                 if(e.getActionCommand()=="button15") {
                       OP4=Math.log(OP1);
                       op=new Double(OP4);
                       result.setText(op.toString(op.doubleValue()));
                       FLAG1=0;
                       FLAG2=-1;
                 }
                 if(e.getActionCommand()=="button16") {
                       FLAG1=16;
                       FLAG2=-1;
                 }
                 if(e.getActionCommand()=="button17") {
                       result.setText("                       ");
                       FLAG1=0;
                       FLAG2=-1;
                 }
                 if(e.getActionCommand()=="button18") {
                       if(FLAG1==0){
                             OP1=-1*OP1;
                             op=new Double(OP1);
                             result.setText(op.toString(op.doubleValue()));
                       }
                       else{
                             OP2=-1*OP2;
                             op=new Double(OP2);
                             result.setText(op.toString(op.doubleValue()));
                       }
                 }
                 if(e.getActionCommand()=="button19") {
                       FLAG2=0;
                 }
                 if(e.getActionCommand()=="button20") {
                       switch(FLAG1){
                             case 4:
                                   OP4=OP1/OP2;
                                   op=new Double(OP4);
                                   result.setText(op.toString(op.doubleValue()));
                                   FLAG1=0;
                                   FLAG2=-1;break;
                             case 8:
                                   OP4=OP1*OP2;
                                   op=new Double(OP4);
                                   result.setText(op.toString(op.doubleValue()));
                                   FLAG1=0;
                                   FLAG2=-1;break;
                             case 12:
                                   OP4=OP1-OP2;
                                   op=new Double(OP4);
                                   result.setText(op.toString(op.doubleValue()));
                                   FLAG1=0;
                                   FLAG2=-1;break;
                             case 16:
                                   OP4=OP1+OP2;
                                   op=new Double(OP4);
                                   result.setText(op.toString(op.doubleValue()));
                                   FLAG1=0;
                                   FLAG2=-1;break;
                        }
                 }
            
       }
       public static void main(String[] args){
              /*counterFrame=new JFrame("Calculator");*/
              try {
               
                       UIManager.setLookAndFeel(
     UIManager.getCrossPlatformLookAndFeelClassName());
     
               } catch (Exception e) {} 
             Calculator calculator1=new Calculator();
             /* counterFrame.add(resultPanel);
            counterFrame.add(keyPanel);
            counterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            counterFrame.pack();
            counterFrame.setVisible(true);*/
       }
    }
      

  2.   

    构建器应为public Calculator(){},那有void啊!
      

  3.   

    counterFrame.add(resultPanel);
    counterFrame.add(keyPanel);改为counterFrame.getContentPane().add(resultPanel);
    counterFrame.getContentPane().add(keyPanel);
      

  4.   

    jFrame.setVisible(true);
    写的好乱阿,ft
      

  5.   

    谢谢zhanghuazhanghome,你是对的,解决了让我们很郁闷的问题
    也代我同学谢谢你