0

I'm trying to make my first calculator (first time using JButtons and all this jazz!) in java and keep hitting issues. Here is the small sliver of code that is giving me problems:

  Numbers n = new Numbers();
  Calculations c = new Calculations();

// ADD ACTION LISTENERS
  one.addActionListener(.n);
  two.addActionListener(n);
  three.addActionListener(n);
  four.addActionListener(n);
  five.addActionListener(n);
  six.addActionListener(n);
  seven.addActionListener(n);
  eight.addActionListener(n);
  nine.addActionListener(n);
  zero.addActionListener(n);

Here is the error message I keep getting:

Calculator.java:105: error: non-static variable this cannot be referenced from a static context
  Numbers n = new Numbers();
              ^
Calculator.java:106: error: non-static variable this cannot be referenced from a static context
  Calculations c = new Calculations();

What's the proper way to make this work? I have tried to declare them a few separate ways, but I continue to either get compiler errors, or what I write is useless because the ActionListeners don't bind with my buttons. If you need to see the whole code, I threw it in a pastebin: HERE. The issue is on line 99.

0 Answers0