perdoname_
asked on
Calculator
Hello Experts,
Can someone give a look to that code ??
It was supposed to be a swing calculator but i cant figure out what's going wrong...
If anyone can help me it'd be grateful!
Thanks in advance!
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionListe ner;
import java.awt.Container;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.*;
public class Calculator extends JFrame implements ActionListener
{
  public static final int Width = 500;
  public static final int Height = 500;
 Â
  private JTextField Board;
  private JButton jbo0, jbo1, jbo2, jbo3, jbo4, jbo5, jbo6, jbo7, jbo8, jbo9,
          jboAddition, jboSubtraction, jboMultiplication, jboDivision,
          jboDot, jboLp, jboRp, jboClear, jboResult;
         Â
  /*        Â
  public static void main(String args[])
 {
  JFrame applet = new Calculator();
  JFrame frame = new JFrame();
  frame.add(frame);
  frame.setSize(Width,Height );
  frame.show();
 }
 */
Â
 public static void main(String args[])
 {
  JFrame outputFrame = new Calculator();
 Â
//panel1.add(allyourstuff) ;
//panel1.add(moreofyourstu ff);
  outputFrame.setVisible(tru e);
 }
  public Calculator()
  {
    Container outputPane = this.getContentPane();
    this.setDefaultCloseOperat ion(JFrame .EXIT_ON_C LOSE);
    this.setSize(Width, Height);
    outputPane.setLayout(new GridLayout (3, 3));
   Â
    Panel panel1 = new Panel();
    this.setDefaultCloseOperat ion( EXIT_ON_CLOSE );
    Board = new JTextField();
    panel1.add(Board);
    outputPane.add(panel1);
    //panel1.add(jbo0);
Â
    //Numbers
    setLayout(new FlowLayout());
    setFont(new Font("Helvetica", Font.PLAIN, 8));
    JButton jbo0 = new JButton("0");
    jbo0.addActionListener(thi s);
    panel1.add(jbo0);
    jbo1 = new JButton("1");
    panel1.add(jbo1);
    jbo1.addActionListener(thi s);
    jbo2 = new JButton("2");
    panel1.add(jbo2);
    jbo2.addActionListener(thi s);
    jbo3 = new JButton("3");
    panel1.add(jbo3);
    jbo3.addActionListener(thi s);
    jbo4 = new JButton("4");
    panel1.add(jbo4);
    jbo4.addActionListener(thi s);
    jbo5 = new JButton("5");
    panel1.add(jbo5);
    jbo5.addActionListener(thi s);
    jbo6 = new JButton("6");
    panel1.add(jbo6);
    jbo6.addActionListener(thi s);
    jbo7 = new JButton("7");
    panel1.add(jbo7);
    jbo7.addActionListener(thi s);
    jbo8 = new JButton("8");
    panel1.add(jbo8);
    jbo8.addActionListener(thi s);
    jbo9 = new JButton("9");
    panel1.add(jbo9);
    jbo9.addActionListener(thi s);
   Â
    //Math Operations
   Â
    jboAddition = new JButton("+");
    panel1.add(jboAddition);
    jboAddition.addActionListe ner(this);
    jboSubtraction = new JButton("-");
    panel1.add(jboSubtraction) ;
    jboSubtraction.addActionLi stener(thi s);
    jboMultiplication = new JButton("*");
    panel1.add(jboMultiplicati on);
    jboMultiplication.addActio nListener( this);
    jboDivision = new JButton("/");
    panel1.add(jboDivision);
    jboDivision.addActionListe ner(this);
   Â
    //Result etc..
   Â
    jboDot = new JButton(".");
    panel1.add(jboDot);
    jboDot.addActionListener(t his);
    jboLp = new JButton("(");
    panel1.add(jboLp);
    jboLp.addActionListener(th is);
    jboRp = new JButton(")");
    panel1.add(jboRp);
    jboRp.addActionListener(th is);
    jboClear = new JButton("C");
    panel1.add(jboClear);
    jboClear.addActionListener (this);
    jboResult = new JButton("=");
    panel1.add(jboResult);
    jboResult.addActionListene r(this);
   Â
  }
 Â
  public void actionPerformed(ActionEven t e)
  {
    if (e.getSource() instanceof JButton)
    {
      JButton buClicked = (JButton) e.getSource();
      if (buClicked == jboClear)
      {
        boardClear();
      }
      else if(buClicked == jboResult)
      {
        Calculate();
      }
    }
    else
    {
      Calculate();
    }
  }
 Â
  public void UserInput(JButton buClicked)
  {
    String input;
    input = Board.getText();
    if (buClicked == jbo0)
    {
      Board.setText(input + "0");
    }
    if (buClicked == jbo1)
    {
      Board.setText(input + "1");
    }
    if (buClicked == jbo2)
    {
      Board.setText(input + "2");
    }
    if (buClicked == jbo3)
    {
      Board.setText(input + "3");
    }
    if (buClicked == jbo4)
    {
      Board.setText(input + "4");
    }
    if (buClicked == jbo5)
    {
      Board.setText(input + "5");
    }
    if (buClicked == jbo6)
    {
      Board.setText(input + "6");
    }
    if (buClicked == jbo7)
    {
      Board.setText(input + "7");
    }
    if (buClicked == jbo8)
    {
      Board.setText(input + "8");
    }
    if (buClicked == jbo9)
    {
      Board.setText(input + "9");
    }
    if (buClicked == jboAddition)
    {
      Board.setText(input + "+");
    }
    if (buClicked == jboSubtraction)
    {
      Board.setText(input + "-");
    }
    if (buClicked == jboMultiplication)
    {
      Board.setText(input + "*");
    }
    if (buClicked == jboDivision)
    {
      Board.setText(input + "/");
    }
    if (buClicked == jboDot)
    {
      Board.setText(input + ".");
    }
    if (buClicked == jboLp)
    {
      Board.setText(input + "(");
    }
    if (buClicked == jboRp)
    {
      Board.setText(input + ")");
    }
  }
 Â
   private void boardClear()
  {
    Board.setText("");
  }
 Â
  public void Calculate()
  {
    int counter;
    int numParenthesis = 0;
    int lenInput;
    String calc;
    String Answer = "";
    char NumOther;
   Â
    calc = Board.getText();
    lenInput = calc.length();
   Â
    for (counter = 0; counter < lenInput; counter++)
    {
      NumOther = calc.charAt(counter);
      if (NumOther == ')')
      {
        numParenthesis--;
      }
      if (NumOther == '(')
      {
        numParenthesis++;
      }
      if ((NumOther < '(') || (NumOther > '9') || (NumOther == '.'))
      {
        Board.setText("Error");
      }
      if (NumOther == '.' && (counter + 1 < calc.length()))
      {
        for (int k = counter + 1; (k < calc.length()) && ((Character.isDigit(calc.c harAt(k))) || ((calc.charAt(k))) == '.'); k++)
        {
          if (calc.charAt(k) == '.')
          {
            Board.setText("Error");
          }
        }
      }
    }
    if (numParenthesis != 0)
    {
      Board.setText("Error");
    }
    else
    {
      Answer = Calculate2(calc);
      Board.setText(Answer);
    }
  }
   Â
  private String CalculatorImp(String oper1, String oper2, char Oper)
  {
    Double op1, op2;
    double ops1, ops2;
    double ans = 0;
    String result;
   Â
    op1 = new Double (oper1);
    op2 = new Double (oper2);
    ops1 = op1.doubleValue();
    ops2 = op2.doubleValue();
   Â
    if (Oper == '+')
    {
      ans = ops1 + ops2;
    }
    if (Oper == '-')
    {
      ans = ops1 - ops2;
    }
    if (Oper == '*')
    {
      ans = ops1 * ops2 ;
    }
    if (Oper == '/')
    {
      ans = ops1/ops2;
    }
   Â
    result = Double.toString(ans);
    return result;
  }
   Â
 Â
  private String Calculate2(String process)
  {
    String answer = process;
    String op1 = "";
    String op2 = "";
    char userinput;
    int index = 0;
    int indexL = 0;
    int indexR = 0;
    int numInput = answer.length();
    int numPar = 0;
    int matchPar = 0;
    int indexOp1 = 0;
    int indexOp2 = 0;
   Â
    if (answer  != "Error")
    {
      for (index = 0; index < numInput; index++)
      {
        userinput = answer.charAt(index);
       Â
        if (userinput  == '(')
        {
          if (matchPar == 0)
          {
            indexOp1 = index;
          }
          matchPar++;
          numPar++;
        }
        if (userinput == ')')
        {
          matchPar--;
          if (matchPar ==0)
          {
            indexOp2 = index;
          }
        }
      }
      if (indexOp1 + 1 == indexOp2)
      {
        Board.setText("Error");
      }
      if (answer == "Error"  && numPar > 0)
      {
        if (indexOp1 == 0)
        {
          if (indexOp2 == (numInput - 1))
          {
            if (indexOp1 != indexOp2)
            {
              answer = Calculate2(answer.substrin g(indexOp1 + 1, indexOp2));
            }
          }
        }
        else if (indexOp1 == 0 && indexOp2 > 0)
        {
          if ((Character.isDigit(answer .charAt(in dexOp2 + 1))))
          {
            Board.setText("Error");
          }
          else
          {
            answer = Calculate2(answer.substrin g(indexOp1 + 1, indexOp2)) + answer.substring(indexOp2 + 1);
            numPar--;
            while (numPar != 0)
            {
              answer = Calculate2(answer);
              numPar--;
            }
          }
        }
        else if ((indexOp1 > 0) && (indexOp2 > 0) && (indexOp2 != numInput - 1))
        {
          if (((Character.isDigit(answe r.charAt(i ndexOp2 + 1 ))) ||  (Character.isDigit(answer. charAt(ind exOp1 - 1 ))) ))
          {
            Board.setText("Error");
          }
          else
          {
            answer = answer.substring(0, indexOp1) + Calculate2(answer.substrin g(indexOp1 + 1, indexOp2)) + answer.substring(indexOp2 + 1);
            numPar--;
            while (numPar != 0)
            {
              answer = Calculate2(answer);
              numPar--;
            }
          }
        }
        else if (indexOp2 == numInput - 1 && indexOp1 > 0)
        {
          if (((Character.isDigit(answe r.charAt(i ndexOp1 - 1)))))
          {
            Board.setText("Error");
          }
          else
          {
            answer = answer.substring(0, indexOp1) + Calculate2(answer.substrin g(indexOp1 + 1, indexOp2));
            numPar--;
            while (numPar != 0)
            {
              answer = Calculate2(answer);
              numPar--;
            }
          }
        }
      }
      if (numPar == 0)
      {
        if (answer != "Error")
        {
          if (!(Character.isDigit(answe r.charAt(0 ))))
          {
            if (answer.charAt(0) != '-')
            {
              if (!(Character.isDigit(answe r.charAt(a nswer.leng th() - 1))))
              {
                Board.setText("Error");
              }
            }
          }
        }
      }
     Â
      for (index = 0; index < answer.length() && (answer == "Error"); index++)
      {
        userinput = answer.charAt(index);
       Â
        if (userinput == '*' || userinput == '/')
        {
          if (!(Character.isDigit(answe r.charAt(i ndex-1))) || (!(Character.isDigit(answe r.charAt(i ndex + 1)))))
          {
            if (answer.charAt(index + 1) != '-')
            {
              Board.setText("Error");
            }
          }
          if (answer.charAt(index + 1) == '-')
          {
            if (!(Character.isDigit(answe r.charAt(i ndex + 2))))
            {
              Board.setText("Error");
            }
          }
          if (answer == "Error")
          {
            indexL = index - 1;
           Â
            if (indexL > 2)
            {
              if ((answer.charAt(indexL - 1)) == '-')
              {
               Â
                  indexL = indexL -2;
               Â
              }
            }
              while ((indexL  > 0) && ((Character.isDigit(answer .charAt(in dexL - 2)) || ((answer.charAt(indexL - 1)) == '.'))))
              {
                indexL--;
              }
              if (indexL == 1)
              {
                if ((answer.charAt(indexL - 1)) == '-')
                {
                  indexL--;
                }
              }
              if (indexL > 2)
              {
                if (((answer.charAt(indexL - 1)) == '-') && !(Character.isDigit(answer .charAt(in dexL - 2))))
                  {
                    indexL--;
                  }
              }
              op2 = answer.substring(index + 1, indexR + 1);
            Â
              }
            }
          }
        }
       Â
       Â
        for (index = 0; index < answer.length() && (answer != "Error"); index++)
        {
          if (index == 0)
          {
            index = 1;
          }
        }
        if (index > 0)
        {
         Â
            if (answer.charAt(index + 1) == '-')
            {
              index = index + 2;
            }
         Â
        }
       Â
        userinput = answer.charAt(index);
       Â
        if ((userinput == '+') || (userinput == '-'))
        {
          if (!(Character.isDigit(answe r.charAt(i ndex - 1))))
          {
            Board.setText("Error");
          }
          if (!(Character.isDigit(answe r.charAt(i ndex + 1))))
          {
            Board.setText("Error");
          }
          if ((answer.charAt(index+1) == '-') && (!(Character.isDigit(answe r.charAt(i ndex+2)))) )
          {
             Board.setText("Error");
          }
          if (answer != "Error")
          {
            indexL = 0;
            op1 = answer.substring(indexL , index);
            indexR = index + 1;
            while((indexR < answer.length()-1) && ((Character.isDigit(answer .charAt(in dexR + 1))) || ((answer.charAt(indexR + 1)) == '.')))
            {
              indexR++;
              if (indexR < answer.length() - 2)
              {
               Â
                  if ((answer.charAt(indexR + 1)) == '-')
                  {
                    indexR++;
                  }
              Â
              }
            }
            op2 = answer.substring(index + 1, indexR + 1);
            answer = CalculatorImp(op1, op2, userinput ) + answer.substring(indexR + 1);
            index = 0;
          }
        }
     Â
   Â
    return answer;
  }
}
Can someone give a look to that code ??
It was supposed to be a swing calculator but i cant figure out what's going wrong...
If anyone can help me it'd be grateful!
Thanks in advance!
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent
import java.awt.event.ActionListe
import java.awt.Container;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.*;
public class Calculator extends JFrame implements ActionListener
{
  public static final int Width = 500;
  public static final int Height = 500;
 Â
  private JTextField Board;
  private JButton jbo0, jbo1, jbo2, jbo3, jbo4, jbo5, jbo6, jbo7, jbo8, jbo9,
          jboAddition, jboSubtraction, jboMultiplication, jboDivision,
          jboDot, jboLp, jboRp, jboClear, jboResult;
         Â
  /*        Â
  public static void main(String args[])
 {
  JFrame applet = new Calculator();
  JFrame frame = new JFrame();
  frame.add(frame);
  frame.setSize(Width,Height
  frame.show();
 }
 */
Â
 public static void main(String args[])
 {
  JFrame outputFrame = new Calculator();
 Â
//panel1.add(allyourstuff)
//panel1.add(moreofyourstu
  outputFrame.setVisible(tru
 }
  public Calculator()
  {
    Container outputPane = this.getContentPane();
    this.setDefaultCloseOperat
    this.setSize(Width, Height);
    outputPane.setLayout(new GridLayout (3, 3));
   Â
    Panel panel1 = new Panel();
    this.setDefaultCloseOperat
    Board = new JTextField();
    panel1.add(Board);
    outputPane.add(panel1);
    //panel1.add(jbo0);
Â
    //Numbers
    setLayout(new FlowLayout());
    setFont(new Font("Helvetica", Font.PLAIN, 8));
    JButton jbo0 = new JButton("0");
    jbo0.addActionListener(thi
    panel1.add(jbo0);
    jbo1 = new JButton("1");
    panel1.add(jbo1);
    jbo1.addActionListener(thi
    jbo2 = new JButton("2");
    panel1.add(jbo2);
    jbo2.addActionListener(thi
    jbo3 = new JButton("3");
    panel1.add(jbo3);
    jbo3.addActionListener(thi
    jbo4 = new JButton("4");
    panel1.add(jbo4);
    jbo4.addActionListener(thi
    jbo5 = new JButton("5");
    panel1.add(jbo5);
    jbo5.addActionListener(thi
    jbo6 = new JButton("6");
    panel1.add(jbo6);
    jbo6.addActionListener(thi
    jbo7 = new JButton("7");
    panel1.add(jbo7);
    jbo7.addActionListener(thi
    jbo8 = new JButton("8");
    panel1.add(jbo8);
    jbo8.addActionListener(thi
    jbo9 = new JButton("9");
    panel1.add(jbo9);
    jbo9.addActionListener(thi
   Â
    //Math Operations
   Â
    jboAddition = new JButton("+");
    panel1.add(jboAddition);
    jboAddition.addActionListe
    jboSubtraction = new JButton("-");
    panel1.add(jboSubtraction)
    jboSubtraction.addActionLi
    jboMultiplication = new JButton("*");
    panel1.add(jboMultiplicati
    jboMultiplication.addActio
    jboDivision = new JButton("/");
    panel1.add(jboDivision);
    jboDivision.addActionListe
   Â
    //Result etc..
   Â
    jboDot = new JButton(".");
    panel1.add(jboDot);
    jboDot.addActionListener(t
    jboLp = new JButton("(");
    panel1.add(jboLp);
    jboLp.addActionListener(th
    jboRp = new JButton(")");
    panel1.add(jboRp);
    jboRp.addActionListener(th
    jboClear = new JButton("C");
    panel1.add(jboClear);
    jboClear.addActionListener
    jboResult = new JButton("=");
    panel1.add(jboResult);
    jboResult.addActionListene
   Â
  }
 Â
  public void actionPerformed(ActionEven
  {
    if (e.getSource() instanceof JButton)
    {
      JButton buClicked = (JButton) e.getSource();
      if (buClicked == jboClear)
      {
        boardClear();
      }
      else if(buClicked == jboResult)
      {
        Calculate();
      }
    }
    else
    {
      Calculate();
    }
  }
 Â
  public void UserInput(JButton buClicked)
  {
    String input;
    input = Board.getText();
    if (buClicked == jbo0)
    {
      Board.setText(input + "0");
    }
    if (buClicked == jbo1)
    {
      Board.setText(input + "1");
    }
    if (buClicked == jbo2)
    {
      Board.setText(input + "2");
    }
    if (buClicked == jbo3)
    {
      Board.setText(input + "3");
    }
    if (buClicked == jbo4)
    {
      Board.setText(input + "4");
    }
    if (buClicked == jbo5)
    {
      Board.setText(input + "5");
    }
    if (buClicked == jbo6)
    {
      Board.setText(input + "6");
    }
    if (buClicked == jbo7)
    {
      Board.setText(input + "7");
    }
    if (buClicked == jbo8)
    {
      Board.setText(input + "8");
    }
    if (buClicked == jbo9)
    {
      Board.setText(input + "9");
    }
    if (buClicked == jboAddition)
    {
      Board.setText(input + "+");
    }
    if (buClicked == jboSubtraction)
    {
      Board.setText(input + "-");
    }
    if (buClicked == jboMultiplication)
    {
      Board.setText(input + "*");
    }
    if (buClicked == jboDivision)
    {
      Board.setText(input + "/");
    }
    if (buClicked == jboDot)
    {
      Board.setText(input + ".");
    }
    if (buClicked == jboLp)
    {
      Board.setText(input + "(");
    }
    if (buClicked == jboRp)
    {
      Board.setText(input + ")");
    }
  }
 Â
   private void boardClear()
  {
    Board.setText("");
  }
 Â
  public void Calculate()
  {
    int counter;
    int numParenthesis = 0;
    int lenInput;
    String calc;
    String Answer = "";
    char NumOther;
   Â
    calc = Board.getText();
    lenInput = calc.length();
   Â
    for (counter = 0; counter < lenInput; counter++)
    {
      NumOther = calc.charAt(counter);
      if (NumOther == ')')
      {
        numParenthesis--;
      }
      if (NumOther == '(')
      {
        numParenthesis++;
      }
      if ((NumOther < '(') || (NumOther > '9') || (NumOther == '.'))
      {
        Board.setText("Error");
      }
      if (NumOther == '.' && (counter + 1 < calc.length()))
      {
        for (int k = counter + 1; (k < calc.length()) && ((Character.isDigit(calc.c
        {
          if (calc.charAt(k) == '.')
          {
            Board.setText("Error");
          }
        }
      }
    }
    if (numParenthesis != 0)
    {
      Board.setText("Error");
    }
    else
    {
      Answer = Calculate2(calc);
      Board.setText(Answer);
    }
  }
   Â
  private String CalculatorImp(String oper1, String oper2, char Oper)
  {
    Double op1, op2;
    double ops1, ops2;
    double ans = 0;
    String result;
   Â
    op1 = new Double (oper1);
    op2 = new Double (oper2);
    ops1 = op1.doubleValue();
    ops2 = op2.doubleValue();
   Â
    if (Oper == '+')
    {
      ans = ops1 + ops2;
    }
    if (Oper == '-')
    {
      ans = ops1 - ops2;
    }
    if (Oper == '*')
    {
      ans = ops1 * ops2 ;
    }
    if (Oper == '/')
    {
      ans = ops1/ops2;
    }
   Â
    result = Double.toString(ans);
    return result;
  }
   Â
 Â
  private String Calculate2(String process)
  {
    String answer = process;
    String op1 = "";
    String op2 = "";
    char userinput;
    int index = 0;
    int indexL = 0;
    int indexR = 0;
    int numInput = answer.length();
    int numPar = 0;
    int matchPar = 0;
    int indexOp1 = 0;
    int indexOp2 = 0;
   Â
    if (answer  != "Error")
    {
      for (index = 0; index < numInput; index++)
      {
        userinput = answer.charAt(index);
       Â
        if (userinput  == '(')
        {
          if (matchPar == 0)
          {
            indexOp1 = index;
          }
          matchPar++;
          numPar++;
        }
        if (userinput == ')')
        {
          matchPar--;
          if (matchPar ==0)
          {
            indexOp2 = index;
          }
        }
      }
      if (indexOp1 + 1 == indexOp2)
      {
        Board.setText("Error");
      }
      if (answer == "Error"  && numPar > 0)
      {
        if (indexOp1 == 0)
        {
          if (indexOp2 == (numInput - 1))
          {
            if (indexOp1 != indexOp2)
            {
              answer = Calculate2(answer.substrin
            }
          }
        }
        else if (indexOp1 == 0 && indexOp2 > 0)
        {
          if ((Character.isDigit(answer
          {
            Board.setText("Error");
          }
          else
          {
            answer = Calculate2(answer.substrin
            numPar--;
            while (numPar != 0)
            {
              answer = Calculate2(answer);
              numPar--;
            }
          }
        }
        else if ((indexOp1 > 0) && (indexOp2 > 0) && (indexOp2 != numInput - 1))
        {
          if (((Character.isDigit(answe
          {
            Board.setText("Error");
          }
          else
          {
            answer = answer.substring(0, indexOp1) + Calculate2(answer.substrin
            numPar--;
            while (numPar != 0)
            {
              answer = Calculate2(answer);
              numPar--;
            }
          }
        }
        else if (indexOp2 == numInput - 1 && indexOp1 > 0)
        {
          if (((Character.isDigit(answe
          {
            Board.setText("Error");
          }
          else
          {
            answer = answer.substring(0, indexOp1) + Calculate2(answer.substrin
            numPar--;
            while (numPar != 0)
            {
              answer = Calculate2(answer);
              numPar--;
            }
          }
        }
      }
      if (numPar == 0)
      {
        if (answer != "Error")
        {
          if (!(Character.isDigit(answe
          {
            if (answer.charAt(0) != '-')
            {
              if (!(Character.isDigit(answe
              {
                Board.setText("Error");
              }
            }
          }
        }
      }
     Â
      for (index = 0; index < answer.length() && (answer == "Error"); index++)
      {
        userinput = answer.charAt(index);
       Â
        if (userinput == '*' || userinput == '/')
        {
          if (!(Character.isDigit(answe
          {
            if (answer.charAt(index + 1) != '-')
            {
              Board.setText("Error");
            }
          }
          if (answer.charAt(index + 1) == '-')
          {
            if (!(Character.isDigit(answe
            {
              Board.setText("Error");
            }
          }
          if (answer == "Error")
          {
            indexL = index - 1;
           Â
            if (indexL > 2)
            {
              if ((answer.charAt(indexL - 1)) == '-')
              {
               Â
                  indexL = indexL -2;
               Â
              }
            }
              while ((indexL  > 0) && ((Character.isDigit(answer
              {
                indexL--;
              }
              if (indexL == 1)
              {
                if ((answer.charAt(indexL - 1)) == '-')
                {
                  indexL--;
                }
              }
              if (indexL > 2)
              {
                if (((answer.charAt(indexL - 1)) == '-') && !(Character.isDigit(answer
                  {
                    indexL--;
                  }
              }
              op2 = answer.substring(index + 1, indexR + 1);
            Â
              }
            }
          }
        }
       Â
       Â
        for (index = 0; index < answer.length() && (answer != "Error"); index++)
        {
          if (index == 0)
          {
            index = 1;
          }
        }
        if (index > 0)
        {
         Â
            if (answer.charAt(index + 1) == '-')
            {
              index = index + 2;
            }
         Â
        }
       Â
        userinput = answer.charAt(index);
       Â
        if ((userinput == '+') || (userinput == '-'))
        {
          if (!(Character.isDigit(answe
          {
            Board.setText("Error");
          }
          if (!(Character.isDigit(answe
          {
            Board.setText("Error");
          }
          if ((answer.charAt(index+1) == '-') && (!(Character.isDigit(answe
          {
             Board.setText("Error");
          }
          if (answer != "Error")
          {
            indexL = 0;
            op1 = answer.substring(indexL , index);
            indexR = index + 1;
            while((indexR < answer.length()-1) && ((Character.isDigit(answer
            {
              indexR++;
              if (indexR < answer.length() - 2)
              {
               Â
                  if ((answer.charAt(indexR + 1)) == '-')
                  {
                    indexR++;
                  }
              Â
              }
            }
            op2 = answer.substring(index + 1, indexR + 1);
            answer = CalculatorImp(op1, op2, userinput ) + answer.substring(indexR + 1);
            index = 0;
          }
        }
     Â
   Â
    return answer;
  }
}
you probably want panel1 to have a GridLayout layout among other things
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.