java - How to retrieve a unique string from Swing components? -


my question has rudimentary answer. i've read tutorials couldn't find specific answer, , i'm starting learn oop concepts.

expected outcome: add focuslistener each component in jpanel, , on focusgained event, retrieve string unique each component (so each text field might have "this field 1", "this field 2", etc.)

problem:

for (component comp : bookcard.getcomponents())         {             comp.addfocuslistener(new focusadapter()             {                 @override                 public void focusgained(focusevent e)                 {                     super.focusgained(e);                      //how implement following line?                     system.out.println(this.getuniquestring());                 }             });         } 

my class hierarchy (correct term?) follows: bookcard extends maincard, maincard extends jpanel. fine.

so kind of hierarchy need solve particular problem? like: mytextfield extends mycomponent, mycomponent extends jcomponent - mycomponent holds getuniquestring() method?

edit: more specific, i'm making dialog similar microsoft word's 'add new source' dialog, grab example string component user. "author" field might "example: kramer, james d".

as far unique name, can use jcomponent.set/getname set unique name each component.


Comments