title: stack overflow error - maybe an infinite loop
body: <p>please excuse my ignorance as I am very new to programming. I'm currently trying to build a calculator project in which I need to have one Jframe class and a Java class. The jframe contains all the interface and the bulk of the calculation is on the java class. What I did is I created a method on the Java class and tried to call it on the Jframe class.</p>
  
  <p>Thanks in advance cheers!
  Here's the code for the Java Class</p>
  
  <pre><code>public class Calculations extends cpCalcFrame {
  
      public double mathoperations()
      {
          String answer;
          secNum = Double.parseDouble(txtOutput.getText());
          switch (operation)
        {
           case "+":
               if(secNum == 0)
               {
                   msgMessage.showMessageDialog(this, "ERROR: Cannot add by zero", "Error Message", javax.swing.JOptionPane.ERROR_MESSAGE);
               }
               else
               {
              result= firstNum + secNum;
              answer = String.format("%.0f", result);
              txtOutput.setText(answer);
              break;
               }
  
           case "-":
               if(secNum == 0)
               {
                   msgMessage.showMessageDialog(this, "ERROR: Cannot subtract by zero", "Error Message", javax.swing.JOptionPane.ERROR_MESSAGE);
               }
               else
               {
              result= firstNum - secNum;
              answer = String.format("%.0f", result);
              txtOutput.setText(answer);           
              break;
               }
  
      case "*":
              if(secNum == 0)
               {
                   msgMessage.showMessageDialog(this, "ERROR: Cannot multiply by zero", "Error Message", javax.swing.JOptionPane.ERROR_MESSAGE);
               }
               else
               {
              result= firstNum * secNum;
              answer = String.format("%.0f", result);
              txtOutput.setText(answer);
              break;
               }
  
           case "/":
               if(secNum == 0)
               {
                   msgMessage.showMessageDialog(this, "ERROR: Cannot divide by zero", "Error Message", javax.swing.JOptionPane.ERROR_MESSAGE);
               }
               else
               {
              result= firstNum / secNum;
              answer = String.format("%.0f", result);
              txtOutput.setText(answer);
  
              break;
               }
  
          }
          return result;
      }
  }
  </code></pre>
  
  <p>and here's my Jframe class code:</p>
  
  <pre><code>public class cpCalcFrame extends javax.swing.JFrame {
  
      public double firstNum;
      public double secNum;
      public double result;
      public String operation;
      **Calculations b = new Calculations();**
      /**
       * Creates new form cpCalcFrame
       */
      public cpCalcFrame() {
          initComponents();
          this.setSize(330, 320);
      }          
  
      private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {                                     
          String input;
          input = txtOutput.getText() + btn1.getText();
          txtOutput.setText(input);
      }                                    
  
      private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {                                     
          String input;
          input = txtOutput.getText() + btn2.getText();
          txtOutput.setText(input);
      }                                    
  
      private void btn3ActionPerformed(java.awt.event.ActionEvent evt) {                                     
          String input;
          input = txtOutput.getText() + btn3.getText();
          txtOutput.setText(input);
      }                                    
  
      private void btn4ActionPerformed(java.awt.event.ActionEvent evt) {                                     
          String input;
          input = txtOutput.getText() + btn4.getText();
          txtOutput.setText(input);
      }                                    
  
      private void btn5ActionPerformed(java.awt.event.ActionEvent evt) {                                     
          String input;
          input = txtOutput.getText() + btn5.getText();
          txtOutput.setText(input);
      }                                    
  
      private void btn6ActionPerformed(java.awt.event.ActionEvent evt) {                                     
          String input;
          input = txtOutput.getText() + btn6.getText();
          txtOutput.setText(input);
      }                                    
  
      private void btn7ActionPerformed(java.awt.event.ActionEvent evt) {                                     
          String input;
          input = txtOutput.getText() + btn7.getText();
          txtOutput.setText(input);
      }                                    
  
      private void btn8ActionPerformed(java.awt.event.ActionEvent evt) {                                     
          String input;
          input = txtOutput.getText() + btn8.getText();
          txtOutput.setText(input);
      }                                    
  
      private void btn9ActionPerformed(java.awt.event.ActionEvent evt) {                                     
          String input;
          input = txtOutput.getText() + btn9.getText();
          txtOutput.setText(input);
      }                                    
  
      private void btn0ActionPerformed(java.awt.event.ActionEvent evt) {                                     
          String input;
          input = txtOutput.getText() + btn0.getText();
          txtOutput.setText(input);
      }                                    
  
      private void btndecActionPerformed(java.awt.event.ActionEvent evt) {                                       
          String input;
          input = txtOutput.getText() + btndec.getText();
          txtOutput.setText(input);
      }                                      
  
      private void btnCAActionPerformed(java.awt.event.ActionEvent evt) {                                      
          txtOutput.setText("");
          firstNum = 0;
          secNum = 0;
      }                                     
  
      private void btnCEActionPerformed(java.awt.event.ActionEvent evt) {                                      
          txtOutput.setText("");
      }                                     
  
      private void btnmultActionPerformed(java.awt.event.ActionEvent evt) {                                        
          firstNum = Double.parseDouble(txtOutput.getText());
          txtOutput.setText("");
          operation = "*";
      }                                       
  
      private void btndivActionPerformed(java.awt.event.ActionEvent evt) {                                       
          firstNum = Double.parseDouble(txtOutput.getText());
          txtOutput.setText("");
          operation = "/";
      }                                      
  
      private void btnaddActionPerformed(java.awt.event.ActionEvent evt) {                                       
          firstNum = Double.parseDouble(txtOutput.getText());
          txtOutput.setText("");
          operation = "+";
      }                                      
  
      private void btnminActionPerformed(java.awt.event.ActionEvent evt) {                                       
          firstNum = Double.parseDouble(txtOutput.getText());
          txtOutput.setText("");
          operation = "-";
      }                                      
  
      **private void btnequalActionPerformed(java.awt.event.ActionEvent evt) {                                         
          b.mathoperations();**
      }                                        
  
      private void btnexclam1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
          if (txtOutput.getText().length() &gt; 0) {
          txtOutput.setText(txtOutput.getText().substring(0, txtOutput.getText().length() - 1));
  }
      }                                          
  </code></pre>