java.awt
Class Window

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
Direct Known Subclasses:
Dialog, Frame

public class Window
extends Container

A Window object is a top-level window with no borders and no menubar. The default layout for a window is BorderLayout.

A window must have either a frame, dialog, or another window defined as its owner when it's constructed.

Windows are capable of generating the following window events: WindowOpened, WindowClosed.

Since:
JDK1.0
See Also:
WindowEvent, addWindowListener(java.awt.event.WindowListener), BorderLayout, Serialized Form

Inner classes inherited from class java.awt.Component
Component.AWTTreeLock, Component.NativeInLightFixer
 
Field Summary
private  boolean active
           
private static String base
           
private  FocusManager focusMgr
          The Focus for the Window in question, and its components.
(package private)  java.awt.im.InputContext inputContext
           
private static int nameCounter
           
(package private) static int OPENED
           
(package private)  Vector ownedWindowList
          A vector containing all the windows this window currently owns.
private static long serialVersionUID
           
(package private)  int state
          An Integer value representing the Window State.
(package private)  String warningString
          This represents the warning message that is to be displayed in a non secure window.
private  java.lang.ref.WeakReference weakThis
           
(package private)  WindowListener windowListener
           
private  int windowSerializedDataVersion
          The window serialized data version.
 
Fields inherited from class java.awt.Container
component, containerListener, containerSerializedDataVersion, dispatcher, layoutMgr, maxSize, ncomponents, serialVersionUID
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, assert, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, hasFocus, height, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, RIGHT_ALIGNMENT, serialVersionUID, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowListenerK, x, y
 
Constructor Summary
(package private) Window()
          Constructs a new window.
  Window(Frame owner)
          Constructs a new invisible window.
  Window(Window owner)
          Constructs a new invisible window with the specified window as its owner.
 
Method Summary
(package private) static void ()
           
 void addNotify()
          Makes this Window displayable by creating the connection to its native screen resource.
(package private)  void addOwnedWindow(java.lang.ref.WeakReference weakWindow)
           
 void addWindowListener(WindowListener l)
          Adds the specified window listener to receive window events from this window.
 void applyResourceBundle(ResourceBundle rb)
          Apply the settings in the given ResourceBundle to this Window.
 void applyResourceBundle(String rbName)
          Load the ResourceBundle with the given name using the default locale and apply its settings to this window.
(package private)  void connectOwnedWindow(Window child)
           
(package private)  String constructComponentName()
          Construct a name for this component.
(package private)  void dispatchEventImpl(AWTEvent e)
           
 void dispose()
          Releases all of the native screen resources used by this Window and its subcomponents.
(package private)  boolean eventEnabled(AWTEvent e)
           
protected  void finalize()
          Disposes of the input methods and context, and removes the WeakReference which formerly pointed to this Window from the parent's owned Window list.
 Component getFocusOwner()
          Returns the child component of this Window which has focus if and only if this Window is active.
 java.awt.im.InputContext getInputContext()
          Gets the input context for this window.
 Locale getLocale()
          Gets the Locale object that is associated with this window, if the locale has been set.
 Window[] getOwnedWindows()
          Return an array containing all the windows this window currently owns.
 Window getOwner()
          Returns the owner of this window.
 Toolkit getToolkit()
          Returns the toolkit of this frame.
 String getWarningString()
          Gets the warning string that is displayed with this window.
private static void initIDs()
          Initialize JNI field and method IDs for fields that may be accessed from C.
(package private)  boolean isActive()
           
 boolean isShowing()
          Checks if this Window is showing on screen.
(package private)  void nextFocus(Component base)
          Deprecated. As of JDK version 1.1, replaced by transferFocus(Component).
private  void ownedInit(Window owner)
           
 void pack()
          Causes this Window to be sized to fit the preferred size and layouts of its subcomponents.
 boolean postEvent(Event e)
          Deprecated. As of JDK version 1.1 replaced by dispatchEvent(AWTEvent).
(package private)  void postProcessKeyEvent(KeyEvent e)
           
(package private)  void postWindowEvent(int id)
           
(package private)  void preProcessKeyEvent(KeyEvent e)
           
protected  void processEvent(AWTEvent e)
          Processes events on this window.
protected  void processWindowEvent(WindowEvent e)
          Processes window events occurring on this window by dispatching them to any registered WindowListener objects.
private  void readObject(ObjectInputStream s)
          Read the default ObjectInputStream, a possibly null listener to receive item events fired by the Window, and a possibly null list of child Windows.
(package private)  void removeOwnedWindow(java.lang.ref.WeakReference weakWindow)
           
 void removeWindowListener(WindowListener l)
          Removes the specified window listener so that it no longer receives window events from this window.
(package private)  void setFocusOwner(Component c)
           
private  void setWarningString()
           
 void show()
          Makes the Window visible.
 void toBack()
          Sends this window to the back.
 void toFront()
          Brings this window to the front.
(package private)  void transferFocus(Component base)
           
private  void writeObject(ObjectOutputStream s)
          Writes default serializable fields to stream.
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyOrientation, countComponents, deliverEvent, dispatchEventToSelf, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getMouseEventTarget, getPreferredSize, getWindow, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPrint, list, list, locate, minimumSize, paint, paintComponents, paramString, postsOldMouseEvents, preferredSize, print, printComponents, printOneComponent, processContainerEvent, proxyEnableEvents, proxyRequestFocus, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getSize, getToolkitImpl, getTreeLock, getWidth, getWindowForObject, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

warningString

String warningString
This represents the warning message that is to be displayed in a non secure window. ie : a window that has a security manager installed for which calling SecurityManager.checkTopLevelWindow() is false. This message can be displayed anywhere in the window.
See Also:
getWarningString()

OPENED

static final int OPENED

state

int state
An Integer value representing the Window State.
See Also:
show()
Since:
JDK1.2

ownedWindowList

transient Vector ownedWindowList
A vector containing all the windows this window currently owns.
See Also:
getOwnedWindows()
Since:
JDK1.2

weakThis

private transient java.lang.ref.WeakReference weakThis

windowListener

transient WindowListener windowListener

active

private transient boolean active

inputContext

transient java.awt.im.InputContext inputContext

focusMgr

private FocusManager focusMgr
The Focus for the Window in question, and its components.
Since:
JDK1.2

base

private static final String base

nameCounter

private static int nameCounter

serialVersionUID

private static final long serialVersionUID

windowSerializedDataVersion

private int windowSerializedDataVersion
The window serialized data version.
Constructor Detail

Window

Window()
Constructs a new window.

First, if there is a security manager, its checkTopLevelWindow method is called with this as its argument to see if it's ok to display the window without a warning banner. If the default implementation of checkTopLevelWindow is used (that is, that method is not overriden), then this results in a call to the security manager's checkPermission method with an AWTPermission("showWindowWithoutWarningBanner") permission. It that method raises a SecurityException, checkTopLevelWindow returns false, otherwise it returns true. If it returns false, a warning banner is created.

See Also:
SecurityManager.checkTopLevelWindow(java.lang.Object)

Window

public Window(Frame owner)
Constructs a new invisible window.

The window is not initially visible. Call the show method to cause the window to become visible.

If there is a security manager, this method first calls the security manager's checkTopLevelWindow method with this as its argument to determine whether or not the window must be displayed with a warning banner.

Parameters:
owner - the main application frame.
Throws:
IllegalArgumentException - if owner is null
See Also:
show(), Component.setSize(int, int), SecurityManager.checkTopLevelWindow(java.lang.Object)

Window

public Window(Window owner)
Constructs a new invisible window with the specified window as its owner.

If there is a security manager, this method first calls the security manager's checkTopLevelWindow method with this as its argument to determine whether or not the window must be displayed with a warning banner.

Parameters:
owner - the window to act as owner
Throws:
IllegalArgumentException - if owner is null
Since:
JDK1.2
See Also:
SecurityManager.checkTopLevelWindow(java.lang.Object)
Method Detail

static void ()

initIDs

private static void initIDs()
Initialize JNI field and method IDs for fields that may be accessed from C.

ownedInit

private void ownedInit(Window owner)

finalize

protected void finalize()
                 throws Throwable
Disposes of the input methods and context, and removes the WeakReference which formerly pointed to this Window from the parent's owned Window list.
Overrides:
finalize in class Object

constructComponentName

String constructComponentName()
Construct a name for this component. Called by getName() when the name is null.
Overrides:
constructComponentName in class Component

addNotify

public void addNotify()
Makes this Window displayable by creating the connection to its native screen resource. This method is called internally by the toolkit and should not be called directly by programs.
Overrides:
addNotify in class Container
Since:
JDK1.0
See Also:
Component.isDisplayable(), Container.removeNotify()

pack

public void pack()
Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated.
See Also:
Component.isDisplayable()

show

public void show()
Makes the Window visible. If the Window and/or its owner are not yet displayable, both are made displayable. The Window will be validated prior to being made visible. If the Window is already visible, this will bring the Window to the front.
Overrides:
show in class Component
See Also:
Component.isDisplayable(), toFront(), Component.setVisible(boolean)

postWindowEvent

void postWindowEvent(int id)

dispose

public void dispose()
Releases all of the native screen resources used by this Window and its subcomponents. That is, the resources for the Window, all of its contained children, and all of its owned Windows will be destroyed, and any memory they consume returned to the OS. The Window and all of its subcomponents will be marked as undisplayable.

The Window and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack or show. The states of the recreated Window and its subcomponents will be identical to the states of these objects at the point where the Window was disposed (not accounting for additional modifcations between those actions).

See Also:
Component.isDisplayable(), getOwnedWindows(), pack(), show()

toFront

public void toFront()
Brings this window to the front. Places this window at the top of the stacking order and shows it in front of any other windows.
See Also:
toBack()

toBack

public void toBack()
Sends this window to the back. Places this window at the bottom of the stacking order and makes the corresponding adjustment to other visible windows.
See Also:
toFront()

getToolkit

public Toolkit getToolkit()
Returns the toolkit of this frame.
Returns:
the toolkit of this window.
Overrides:
getToolkit in class Component
See Also:
Toolkit, Toolkit.getDefaultToolkit(), Component.getToolkit()

getWarningString

public final String getWarningString()
Gets the warning string that is displayed with this window. If this window is insecure, the warning string is displayed somewhere in the visible area of the window. A window is insecure if there is a security manager, and the security manager's checkTopLevelWindow method returns false when this window is passed to it as an argument.

If the window is secure, then getWarningString returns null. If the window is insecure, this method checks for the system property awt.appletWarning and returns the string value of that property.

Returns:
the warning string for this window.
See Also:
SecurityManager.checkTopLevelWindow(java.lang.Object)

setWarningString

private void setWarningString()

getLocale

public Locale getLocale()
Gets the Locale object that is associated with this window, if the locale has been set. If no locale has been set, then the default locale is returned.
Returns:
the locale that is set for this window.
Overrides:
getLocale in class Component
Since:
JDK1.1
See Also:
Locale

getInputContext

public java.awt.im.InputContext getInputContext()
Gets the input context for this window. A window always has an input context, which is shared by subcomponents unless they create and set their own.
Overrides:
getInputContext in class Component
Since:
JDK1.2
See Also:
Component.getInputContext()

getOwner

public Window getOwner()
Returns the owner of this window.

getOwnedWindows

public Window[] getOwnedWindows()
Return an array containing all the windows this window currently owns.
Since:
JDK1.2

addWindowListener

public void addWindowListener(WindowListener l)
Adds the specified window listener to receive window events from this window. If l is null, no exception is thrown and no action is performed.
Parameters:
l - the window listener

removeWindowListener

public void removeWindowListener(WindowListener l)
Removes the specified window listener so that it no longer receives window events from this window. If l is null, no exception is thrown and no action is performed.
Parameters:
l - the window listener

eventEnabled

boolean eventEnabled(AWTEvent e)
Overrides:
eventEnabled in class Container

isActive

boolean isActive()

processEvent

protected void processEvent(AWTEvent e)
Processes events on this window. If the event is an WindowEvent, it invokes the processWindowEvent method, else it invokes its superclass's processEvent.
Parameters:
e - the event
Overrides:
processEvent in class Container

processWindowEvent

protected void processWindowEvent(WindowEvent e)
Processes window events occurring on this window by dispatching them to any registered WindowListener objects. NOTE: This method will not be called unless window events are enabled for this component; this happens when one of the following occurs: a) A WindowListener object is registered via addWindowListener() b) Window events are enabled via enableEvents()
Parameters:
e - the window event
See Also:
Component.enableEvents(long)

preProcessKeyEvent

void preProcessKeyEvent(KeyEvent e)
Overrides:
preProcessKeyEvent in class Container

postProcessKeyEvent

void postProcessKeyEvent(KeyEvent e)
Overrides:
postProcessKeyEvent in class Container

setFocusOwner

void setFocusOwner(Component c)
Overrides:
setFocusOwner in class Container

transferFocus

void transferFocus(Component base)
Overrides:
transferFocus in class Container

getFocusOwner

public Component getFocusOwner()
Returns the child component of this Window which has focus if and only if this Window is active.
Returns:
the component with focus, or null if no children have focus assigned to them.

nextFocus

void nextFocus(Component base)
Deprecated. As of JDK version 1.1, replaced by transferFocus(Component).
Overrides:
nextFocus in class Container

dispatchEventImpl

void dispatchEventImpl(AWTEvent e)
Overrides:
dispatchEventImpl in class Container

postEvent

public boolean postEvent(Event e)
Deprecated. As of JDK version 1.1 replaced by dispatchEvent(AWTEvent).
Overrides:
postEvent in class Component

isShowing

public boolean isShowing()
Checks if this Window is showing on screen.
Overrides:
isShowing in class Component
See Also:
Component.setVisible(boolean)

applyResourceBundle

public void applyResourceBundle(ResourceBundle rb)
Apply the settings in the given ResourceBundle to this Window. Currently, this applies the ResourceBundle's ComponentOrientation to this Window and all components contained within it.
Since:
JDK1.2
See Also:
ComponentOrientation

applyResourceBundle

public void applyResourceBundle(String rbName)
Load the ResourceBundle with the given name using the default locale and apply its settings to this window. Currently, this applies the ResourceBundle's ComponentOrientation to this Window and all components contained within it.
Since:
JDK1.2
See Also:
ComponentOrientation

addOwnedWindow

void addOwnedWindow(java.lang.ref.WeakReference weakWindow)

removeOwnedWindow

void removeOwnedWindow(java.lang.ref.WeakReference weakWindow)

connectOwnedWindow

void connectOwnedWindow(Window child)

writeObject

private void writeObject(ObjectOutputStream s)
                  throws IOException
Writes default serializable fields to stream. Writes a list of serializable ItemListener(s) as optional data. The non-serializable ItemListener(s) are detected and no attempt is made to serialize them. Write a list of child Windows as optional data.
Overrides:
writeObject in class Container
See Also:
AWTEventMulticaster.save(ObjectOutputStream, String, EventListener), java.awt.Component.itemListenerK, java.awt.Component.ownedWindowK

readObject

private void readObject(ObjectInputStream s)
                 throws ClassNotFoundException,
                        IOException
Read the default ObjectInputStream, a possibly null listener to receive item events fired by the Window, and a possibly null list of child Windows. Unrecognised keys or values will be Ignored.
Overrides:
readObject in class Container
See Also:
removeActionListener(), addActionListener()