• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Traking JFrame window events

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
reply
    Bookmark Topic Watch Topic
  • New Topic