My question probably has a rudimentary answer. I've read some tutorials but couldn't find a specific answer, and I'm only just starting to learn OOP concepts.
Expected outcome: Add a focusListener to each component in a JPanel, and on that focusGained event, retrieve a String unique to each component (So each text field might have "this is field 1", "this is field 2", etc.)
Problem:
for (Component comp : bookCard.getComponents())
{
comp.addFocusListener(new FocusAdapter()
{
@Override
public void focusGained(FocusEvent e)
{
super.focusGained(e);
//How do I implement the following line?
System.out.println(this.getUniqueString());
}
});
}
My class hierarchy (correct term?) is as follows: BookCard extends MainCard, MainCard extends JPanel. This is fine.
So what kind of hierarchy will I need to solve this particular problem? Something like: MyTextField extends MyComponent, MyComponent extends JComponent - where MyComponent holds the getUniqueString() method?
Edit: To be more specific, I'm making a dialog similar to Microsoft Word's 'add new source' dialog, which would grab an example String from the component to help the user. "Author" field might say "Example: Kramer, James D".