Hello fellow developers,
Does anyone know why I keep getting this error message "illegal start of expression"? I've already checked my braces. They matched. Still.....[This is code for the basic operation of a calculator n my code is as follows]
public void button2_actionPerformed(ActionEvent e) {
applyOperator('+');
}
public void button14_actionPerformed(ActionEvent e) {
applyOperator('-');
}
public void button13_actionPerformed(ActionEvent e) {
applyOperator('*');
}
public void button12_actionPerformed(ActionEvent e) {
applyOperator('/');
}
private void applyOperator(String theOperator){
if (theOperator == '+'){
public void actionPerformed_Plus(){ //Illegal start of expression here
if (firstTime){
String firstNumber;
firstNumber = textField1.getText();
Double numberDouble1 = Double.valueOf(firstNumber);
number1 = numberDouble1.doubleValue();
result = result + number1;
String displayResult = String.valueOf(result);
textField1.setText(displayResult);
operator = '+';}
else{
String firstNumber;
firstNumber = textField1.getText();
Double numberDouble1 = Double.valueOf(firstNumber);
number1 = numberDouble1.doubleValue();
textField1.setText(firstNumber);
operator = '+';
firstTime = false;}
}
}else if(theOperator=='-'){
public void actionPerformed_Minus() { //Illegal start of expression here
if (firstTime) {
String firstNumber;
firstNumber = textField1.getText();
Double numberDouble1 = Double.valueOf(firstNumber);
number1 = numberDouble1.doubleValue();
result = result - number1;
String displayResult = String.valueOf(result);
textField1.setText(displayResult);
operator = '-';
} else {
String firstNumber;
firstNumber = textField1.getText();
Double numberDouble1 = Double.valueOf(firstNumber);
number1 = numberDouble1.doubleValue();
textField1.setText(firstNumber);
operator = '-';
firstTime = false;
} } //Illegal start of expression here
}else if(theOperator =='*'){
public void actionPerformed_Multiply() {
if (firstTime){
String firstNumber;
firstNumber = textField1.getText();
Double numberDouble1 = Double.valueOf(firstNumber);
number1 = numberDouble1.doubleValue();
result = result * number1;
String displayResult = String.valueOf(result);
textField1.setText(displayResult);
operator = '*';}
else{
String firstNumber;
firstNumber = textField1.getText();
Double numberDouble1 = Double.valueOf(firstNumber);
number1 = numberDouble1.doubleValue();
textField1.setText(firstNumber);
operator = '*';
firstTime = false; }
}
}else if(theOperator == '/'){
public void actionPerformed_Divide() { //Illegal start of expression here
if (firstTime) {
String firstNumber;
firstNumber = textField1.getText();
Double numberDouble1 = Double.valueOf(firstNumber);
number1 = numberDouble1.doubleValue();
result = result / number1;
String displayResult = String.valueOf(result);
textField1.setText(displayResult);
operator = '/'; }
else{
String firstNumber;
firstNumber = textField1.getText();
Double numberDouble1 = Double.valueOf(firstNumber);
number1 = numberDouble1.doubleValue();
textField1.setText(firstNumber);
operator = '/';
firstTime = false; }
}
}else{
result = number1; }
return result;
}
}
Thanks in advance.