aditya parikh
aditya parikh

Reputation: 595

JFrame LifeCycle

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

Answers (2)

remigio
remigio

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 FocusEvents. You can refer to the JFrame documentation for more detailed explanation.

Upvotes: 3

MadProgrammer
MadProgrammer

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

Related Questions