title: Java GUI Calculator calculation error
body: <p>I need some help about Java GUI calculator.</p>
  
  <p>Code is working fine for first calculation when I try to add 5 + 2 it gave me answer 7.</p>
  
  <p>But when I try to make another multiply, addition ,minus etc calculation it give me error. I cant add anything to founded answer.</p>
  
  <p>I know the problem but I don't know how to fix it.</p>
  
  <pre><code>String.format("%1$,.2f", result); 
  </code></pre>
  
  <p>This cause problem. </p>
  
  <p>Sorry for my bad English.</p>
  
  <pre><code>double firstnumb;
  double secnumb;
  double result;
  String operations;
  String ans;
  
  public Calculator() {
      initComponents();
  
  
      jTextField1.setText("");
  
  }
  
  
  
  private void operators () {         
      switch (operations) {
  
          case "+": 
              result=firstnumb+secnumb;
                ans=String.format("%1$,.2f", result);
          jTextField1.setText(ans);
          break;
          case "-":
              result=firstnumb-secnumb;
                ans=String.format("%1$,.2f", result);
          jTextField1.setText(ans);
          break;
          case "*":
              result=firstnumb*secnumb;
           ans=String.format("%1$,.2f", result);
          jTextField1.setText(ans);
          break;
          case "/":
              result=firstnumb/secnumb;
            ans=String.format("%1$,.2f", result);
          jTextField1.setText(ans);
          break;
          case "%":
              result=firstnumb%secnumb;
            ans=String.format("%1$,.2f", result);
          jTextField1.setText(ans);break;
          default: jTextField1.setText("");break;
  
      }
  
  }
  
  private void BtnMultiplyActionPerformed(java.awt.event.ActionEvent evt)   
  {                                            
     firstnumb=Double.parseDouble(jTextField1.getText());
      jTextField1.setText("");
  
      operations="*";
         jTextField2.setText(firstnumb + operations);
  
  }                                           
  
  private void BtnCActionPerformed(java.awt.event.ActionEvent evt)       
  {                                     
     jTextField1.setText("");
     jTextField2.setText("");
  }                                    
  
  private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  
  
      jTextField1.setText(jTextField1.getText()+ "1");
  
  }                                        
  
  private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {                                          
       jTextField1.setText(jTextField1.getText()+ "2");
  }                                         
  
  private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  
      jTextField1.setText(jTextField1.getText()+ "3");
  }                                         
  
  private void jButton21ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  
      jTextField1.setText(jTextField1.getText()+ "4");
  }                                         
  
  private void jButton22ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  
      jTextField1.setText(jTextField1.getText()+ "5");
  }                                         
  
  private void jButton23ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  
      jTextField1.setText(jTextField1.getText()+ "6");
  }                                         
  
  private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  
      jTextField1.setText(jTextField1.getText()+ "7");
  }                                        
  
  private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  
      jTextField1.setText(jTextField1.getText()+ "8");
  }                                         
  
  private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  
      jTextField1.setText(jTextField1.getText()+ "9");
  }                                         
  
  private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  
      jTextField1.setText(jTextField1.getText()+ "0");
  }                                         
  
  private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  
      jTextField1.setText(jTextField1.getText()+ ".");
  }                                         
  
  private void BtnCEActionPerformed(java.awt.event.ActionEvent evt) {                                      
       jTextField1.setText("");
       jTextField2.setText("");
  }                                     
  
  private void BtnEqualActionPerformed(java.awt.event.ActionEvent evt) {                                         
  
  
      secnumb=Double.parseDouble(jTextField1.getText());
  
          operators();
  
  
  }                                        
  
  private void BtnAdditionActionPerformed(java.awt.event.ActionEvent evt) {                                            
  
      firstnumb=Double.parseDouble(jTextField1.getText());
      jTextField1.setText("");
      operations="+";
       jTextField2.setText(firstnumb + operations);
  }                                           
  
  private void BtnMinusActionPerformed(java.awt.event.ActionEvent evt) {                                         
       firstnumb=Double.parseDouble(jTextField1.getText());
      jTextField1.setText("");
      operations="-";
       jTextField2.setText(firstnumb + operations);
  }                                        
  
  private void BtnDivideActionPerformed(java.awt.event.ActionEvent evt) {                                          
        firstnumb=Double.parseDouble(jTextField1.getText());
      jTextField1.setText("");
      operations="/";
       jTextField2.setText(firstnumb + operations);
  }                                         
  
  private void BtnModActionPerformed(java.awt.event.ActionEvent evt) {                                       
    firstnumb=Double.parseDouble(jTextField1.getText());
      jTextField1.setText("");
      operations="%";
       jTextField2.setText(firstnumb + operations);
  }                                      
  
  private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  
      double ops = Double.parseDouble (String.valueOf (jTextField1.getText()));
      ops=ops * (-1);
      jTextField1.setText(String.valueOf(ops));
  
  }                                        
  </code></pre>