Window

A Window is a top-level display area that exists outside the browser or applet area you are working in. It has no adornments, such as the borders, window title, or menu bar that a typical window manager might provide. A Frame is a subclass of Window that adds these parts (borders, window title). Normally you will work with the children of Window and not Window directly. However, you might use a Window to create your own pop-up menu or some other GUI component that requires its own window and isn't provided by AWT. This technique isn't as necessary in Java 1.1, which has a PopupMenu component.

The default LayoutManager for Window is BorderLayout, which is described in BorderLayout.

Window Methods

Constructors

Example 6.1: Finding a Parent Frame

import java.awt.*;
public class ComponentUtilities {
 public static Frame getTopLevelParent (Component component) {
 Component c = component; while (c.getParent() != null) c = c.getParent(); if (c instanceof Frame) return (Frame)c; 
else return null;
}
} 
Appearance methods

A handful of methods assist with the appearance of the Window.

Miscellaneous methods

Window Events

In Java 1.0, a Window peer generates all the events that are generated by the Component class; it does not generate events that are specific to a particular type of component. That is, it generates key events, mouse events, and focus events; it doesn't generate action events or list events. If an event occurs within a child component of a Window, the target of the event is the child component, not the Window.

In addition to the Component events, five events are specific to windows, none of which are passed on by the window's peer. These events happen at the Frame and Dialog level. The events are WINDOW_DESTROY, WINDOW_EXPOSE, WINDOW_ICONIFY, WINDOW_DEICONIFY, and WINDOW_MOVED. The default event handler, handleEvent(), doesn't call a convenience method to handle any of these events. If you want to work with them, you must override handleEvent(). See Frame Events for an example that catches the WINDOW_DESTROY event.

Listeners and 1.1 event handling

With the 1.1 event model, you register listeners for different event types; the listeners are told when the event happens. These methods register listeners and let the Window component inspect its own events.