title: Calculator GUI problems
body: <p>I'm in my first semester of programming as a first year college and we were tasked to make a calculator GUI. I'm almost done but I need to make the &quot;Error&quot; appear if the denominator is 0 but it outputs 0.0. My other problem is that I need the gui to restart after showing the final answer but what happens is that after I clicked equals then clicked the number it just continues. So if I press 1+1 then clicked =, it outputs 2 but when I clicked a number for example 1, it just becomes 21.</p>
  <p>Also, how do I remove the .0 at the end of every answer? I tried endsWith and replace after every equation but it's not working.</p>
  <pre><code> @Override
  public void actionPerformed(ActionEvent e){
      for(int i=0;i&lt;10;i++) {
          if(e.getSource() == numbers[i]) {
              text.setText(text.getText().concat(String.valueOf(i)));
          }
      }
      if(e.getSource()==dec) {
          if (text.getText().contains(&quot;.&quot;)) {
              return;
          } else {
              text.setText(text.getText() + &quot;.&quot;);
          }
      }
      if(e.getSource()==add) {
          num1 = Double.parseDouble(text.getText());
          operator ='+';
          label.setText(text.getText() + &quot;+&quot;);
          text.setText(&quot;&quot;);
      }
      if(e.getSource()==sub) {
          num1 = Double.parseDouble(text.getText());
          operator ='-';
          label.setText(text.getText() + &quot;-&quot;);
          text.setText(&quot;&quot;);
      }
      if(e.getSource()==mult) {
          num1 = Double.parseDouble(text.getText());
          operator ='*';
          label.setText(text.getText() + &quot;*&quot;);
          text.setText(&quot;&quot;);
      }
      if(e.getSource()==div) {
          num1 = Double.parseDouble(text.getText());
          operator ='/';
          label.setText(text.getText() + &quot;/&quot;);
          text.setText(&quot;&quot;);
      }
      if(e.getSource()==neg) {
          Double neg = Double.parseDouble(text.getText());
          neg*=-1;
          text.setText(String.valueOf(neg));
      }
      if(e.getSource()==per) {
          num1 = Double.parseDouble(text.getText())/100;
          label.setText(text.getText() + &quot;%&quot;);
          text.setText(String.valueOf(num1));
          label.setText(&quot;&quot;);
      }
      
      
      if(e.getSource()==equ) {
          num2=Double.parseDouble(text.getText());
          switch(operator) {
          case'+':
              ans=num1+num2;
              break;
          case'-':
              ans=num1-num2;
              break;
          case'*':
              ans=num1*num2;
              break;
          case'/':
              if (num2==0)
                  text.setText(&quot;Error&quot;);
                  else
                      ans=num1/num2;
              break;
          }
          label.setText(&quot;&quot;);
          text.setText(String.valueOf(ans));
      }
      }
      }   
      }
  </code></pre>