Reputation: 595
Similar to start method in applet which gets called when applet window is minimized and maximized, is there some similar method which gets called when we switch control back and forth between JFrame and some other windows (such as notepad) ??
Upvotes: 1
Views: 1989
Reputation: 4211
In Java Swing every kind of Window
, including JFrame
which itself extends the Window
class, can listen to focus events and so can be notified when gaining or losing focus. Just call the addWindowFocusListener
on your JFrame
object, passing a WindowFocusListener
object that will receive and deal with FocusEvent
s.
You can refer to the JFrame documentation for more detailed explanation.
Upvotes: 3
Reputation: 347314
I believe your looking for WindowListener#windowActivated and WindowListener#windowdeactivated
You need to attach a listener to the frame via JFrame#addWindowListener
Upvotes: 3