Question: I need to set up a listener that can call a method every time a `show()` method is invoked to display a window. How can I do this?

Answer: 
You'd probably be interested in `WindowListener`.

From [the tutorial, "How to Write Window Listeners"](http://docs.oracle.com/javase/tutorial/uiswing/events/windowlistener.html):

> 
> The following window activities or states can precede a window event:
> 
> 
> * Opening a window — Showing a window for the first time.
> * Closing a window — Removing the window from the screen.
> * Iconifying a window — Reducing the window to an icon on the desktop.
> * Deiconifying a window — Restoring the window to its original size.
> * Focused window — The window which contains the "focus owner".
> * Activated window (frame or dialog) — This window is either the focused window, or owns the focused window.
> * Deactivated window — This window has lost the focus. For more information about focus, see the AWT Focus Subsystem specification.
> 
> 
> 

If you don't want to have to implement all of them, you could use a [`WindowAdapter`](http://docs.oracle.com/javase/7/docs/api/java/awt/event/WindowAdapter.html), as follows:

```
myFrame.addWindowListener(new WindowAdapter() {
    @Override
    public void windowOpened(WindowEvent we) {
        System.out.println("this window was opened for the first time");
    }

    @Override
    public void windowActivated(WindowEvent we) {
        System.out.println("this window or a subframe was focused");
    }
});

```
There is an interface called [WindowListener](http://docs.oracle.com/javase/7/docs/api/java/awt/event/WindowListener.html) and here is a event that gets fired when window is [opened](http://docs.oracle.com/javase/7/docs/api/java/awt/event/WindowListener.html#windowOpened%28java.awt.event.WindowEvent%29).You can find all the events in the first link.

**EDIT :**

The WindowListener works only once. As Per @Andrew Thompson's post we should be using ComponentListener. Certainly **the best answer**.