The problem is basically this:
class Herons {
static JTextField a;
Herons() {
JTextField a = new JTextField(); // 'a' is shadowed
}
}
When you say JTextField a = ...
in the constructor it declares a different local variable called a
and shadows the field.
It should be like this:
Herons() {
a = new JTextField(); // field 'a' is assigned
}
Otherwise you may have noticed that when you tried to call getText
on your fields they were null in actionPerformed
.
I found this page about hiding/shadowing if you want to read more.
As a side note, your variables also do not need to be static (and maybe shouldn't be since you're creating an instance of the class to refer to them).