Problems with Inner classes
I understand inner classes and have used them a bit before(mostly for actionhandling)
This problem deals with an innerclass for actionhandling on a calculator. I originally had lots of repetitive handling as anonymous inner class where only one thing changes on each button.
I switched to code to this, which allows me to specify which number to display
Code:
public class Calculator{
//create button
class NumberHandling implements ActionListener{
String number;
private NumberHandling(String number){
this.number = number;
}
public void actionPerformed(ActionEvent e){
if(clearView){
view.setText(number);
clearView = false;
}
else{
StringBuilder str = new StringBuilder(view.getText());
str.append(number);
view.setText(str.toString());
}
displayLabel.setText(displayLabel.getText() + number);
}
}
}
My problem is the fact that I have to make the inner class be
Code:
class ClassName implements ActionListener{
When I tried
Code:
private class ClassName implements ActionListener{
I received an illegal start of expression error.
When I changed it to
Code:
private static class ClassName implements ActionListener{
I got 100 errors.
Im just wondering why it's complaining about having the inner class having any sort of access modifier.