posted 14 years ago
Michael provides a big hint when he asks how the textfields are "seen" by this class, and per your code it appears that this class in fact has no way of seeing or getting a reference to the JTextFields. Because of this, I am surprised that this class even compiles.
A suggestion:
1) Give your GUI class, the one that holds the JTextFields, a public method, say clearTextFields(), and inside this method do just that, set all the JTextField texts to "".
2) Give your ClearHandler class a GUI variable and in the ClearHandler constructor, pass a reference to the main GUI.
3) In the ClearHandler's actionPerformed method call the clearTextFields() method off of the GUI.
edit: OK, I see why your code compiles and what you're doing wrong. Your handler class extend from the gui class, and yes by doing this it will "see" the fields of the gui, but you must understand that these JTextFields that handler sees are handler's own non-displayed JTextFields and have nothing to do with the ones that are held by the GUIApps object that is displayed, that the handler class inherits completely different objects. You don't use inheritance for this for as you're seeing it simply doesn't work and it's wrong because the Handler class does not fulfill the "is-a" requirement for inheritance: in other words, it isn't inherently a more specialsed type of the GUIApps class and never will be. Instead, pass a reference from the actual GUI to your class as I suggest above and demonstrate below:
e.g.,