Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Traking JFrame window events  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know how to write a window listener class. But I have always only written one for a single JFrame. Is it possoble to implement window listener in one class and invoke this class on multiple JFrames in one app?
I am assuming that the answer to this question is yes, and if so, when I getSource() in the event windowEvent method how do I know which Window/JFrame is active? Do I gain that from the windowActivated() method?
Thanks.
 
Shashi Kanta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, u have to use getSource() of WindowEvent in windoActivated() method to get the name of the frame object.
however u have to add the WindowListener to each frame instance or inside each frame's constructor.
rgds,
Shashi
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have successfully achieved what I was trying for. But I have another question and thought I would just post it along with this post since it is related.
Is the singleton method safe to use on a WindowListener like this and just create an object reference to the WindowListener object? Or should I just create a new WindowListener object for each individual frame?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!