Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Recommendation on Listener location.  RSS feed

 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Created a simple sample where a Frame is created and a table added via the call: frame.add(new JScrollPane(table));

A WindowListener was added to the Frame and the table passed in via the call: frame.addWindowListener(new MyWindowListener(table) );

Code was added to the windowClosing and windowOpened methods to do some work specific to this Table when the table is first opened and when it is closed. All works fine.

Attempting to expand this sample so the Frame can housed different tables (Table1, Table2....) at different times.

My dilemma now is to try and figure out where to place the code doing the work as Table1, Table2.... would all do different things but it would be done when the table is first opened and when closed.

What type of Listener would be best and where would it be best location to incorporate such a listener?
 
Campbell Ritchie
Marshal
Posts: 55704
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Difficult to be sure; there are lots of different kinds of Listeners; the Java Tutorials describe twenty‑three different kinds. The basic EventListener interface has 72 subinterfaces listed.
I don't understand about using a window listener to add a scroll pane. You would usually add components in the constructor/initGUI method, and they would not change while running, although some might appear or be hidden at different times (e.g. Dialogues, Card Layout).
If you are using buttons to open tables, or add data from files, you might do well to consider action listeners on those buttons. Action listener is what the Java Tutorials call a high‑level listener, and they also say to use the highest‑level listener you can.
 
Sam Gooding
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Landry wrote:Created a simple sample where a Frame is created and a table added via the call: frame.add(new JScrollPane(table));

A WindowListener was added to the Frame and the table passed in via the call: frame.addWindowListener(new MyWindowListener(table) );

Code was added to the windowClosing and windowOpened methods to do some work specific to this Table when the table is first opened and when it is closed. All works fine.

Attempting to expand this sample so the Frame can housed different tables (Table1, Table2....) at different times.

My dilemma now is to try and figure out where to place the code doing the work as Table1, Table2.... would all do different things but it would be done when the table is first opened and when closed.

What type of Listener would be best and where would it be best location to incorporate such a listener?



This part has me confused:

the code doing the work as Table1, Table2.


can you describe that entity in other words ? what is "the work" ?


 
Campbell Ritchie
Marshal
Posts: 55704
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

We do sometimes get vague questions like that, and don't always get such clarification.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!