G
G. Ralph Kuntz, MD
I am trying to find a way to get a field's name (variable name) given a
pointer to "this".
I am trying to log all user actions in an application. In every case
where a JButton appears in my app, I use a subclass:
JButton aButton = new MyButton();
I can modify the constructor for MyButton to automatically log when the
button is clicked by adding an ActionListener. I would like to print
the class of the containing window (JDialog or JFrame) and the variable
name of the button. This way I can recreate what the user clicked.
I realize that I could use getClass().getFields() and loop thought the
Field[] until I find "this" then use Field.getName(), but I was hoping
for a faster way (less impact on performance).
Any ideas?
pointer to "this".
I am trying to log all user actions in an application. In every case
where a JButton appears in my app, I use a subclass:
JButton aButton = new MyButton();
I can modify the constructor for MyButton to automatically log when the
button is clicked by adding an ActionListener. I would like to print
the class of the containing window (JDialog or JFrame) and the variable
name of the button. This way I can recreate what the user clicked.
I realize that I could use getClass().getFields() and loop thought the
Field[] until I find "this" then use Field.getName(), but I was hoping
for a faster way (less impact on performance).
Any ideas?