📄 window.java
字号:
if (peer != null) { WindowPeer wp = (WindowPeer) peer; wp.toBack(); } } /** * Brings this window to the front so that it displays in front of * any other windows. */ public void toFront() { if (peer != null) { WindowPeer wp = (WindowPeer) peer; wp.toFront(); } } /** * Returns the toolkit used to create this window. * * @return The toolkit used to create this window. * * @specnote Unlike Component.getToolkit, this implementation always * returns the value of Toolkit.getDefaultToolkit(). */ public Toolkit getToolkit() { return Toolkit.getDefaultToolkit(); } /** * Returns the warning string that will be displayed if this window is * popped up by an unsecure applet or application. * * @return The unsecure window warning message. */ public final String getWarningString() { return warningString; } /** * Returns the locale that this window is configured for. * * @return The locale this window is configured for. */ public Locale getLocale() { return locale == null ? Locale.getDefault() : locale; } /* /** @since 1.2 public InputContext getInputContext() { // FIXME } */ /** * Sets the cursor for this window to the specifiec cursor. * * @param cursor The new cursor for this window. */ public void setCursor(Cursor cursor) { super.setCursor(cursor); } public Window getOwner() { return (Window) parent; } /** @since 1.2 */ public Window[] getOwnedWindows() { Window [] trimmedList; synchronized (getTreeLock ()) { // Windows with non-null weak references in ownedWindows. Window [] validList = new Window [ownedWindows.size()]; Iterator e = ownedWindows.iterator(); int numValid = 0; while (e.hasNext()) { Window w = (Window)(((Reference) e.next()).get()); if (w != null) validList[numValid++] = w; else // Remove null weak reference from ownedWindows. e.remove(); } if (numValid != validList.length) { trimmedList = new Window [numValid]; System.arraycopy (validList, 0, trimmedList, 0, numValid); } else trimmedList = validList; } return trimmedList; } /** * Adds the specified listener to the list of <code>WindowListeners</code> * that will receive events for this window. * * @param listener The <code>WindowListener</code> to add. */ public synchronized void addWindowListener(WindowListener listener) { windowListener = AWTEventMulticaster.add(windowListener, listener); } /** * Removes the specified listener from the list of * <code>WindowListeners</code> that will receive events for this window. * * @param listener The <code>WindowListener</code> to remove. */ public synchronized void removeWindowListener(WindowListener listener) { windowListener = AWTEventMulticaster.remove(windowListener, listener); } /** * Returns an array of all the window listeners registered on this window. * * @since 1.4 */ public synchronized WindowListener[] getWindowListeners() { return (WindowListener[]) AWTEventMulticaster.getListeners(windowListener, WindowListener.class); } /** * Returns an array of all the window focus listeners registered on this * window. * * @since 1.4 */ public synchronized WindowFocusListener[] getWindowFocusListeners() { return (WindowFocusListener[]) AWTEventMulticaster.getListeners(windowFocusListener, WindowFocusListener.class); } /** * Returns an array of all the window state listeners registered on this * window. * * @since 1.4 */ public synchronized WindowStateListener[] getWindowStateListeners() { return (WindowStateListener[]) AWTEventMulticaster.getListeners(windowStateListener, WindowStateListener.class); } /** * Adds the specified listener to this window. */ public void addWindowFocusListener (WindowFocusListener wfl) { windowFocusListener = AWTEventMulticaster.add (windowFocusListener, wfl); } /** * Adds the specified listener to this window. * * @since 1.4 */ public void addWindowStateListener (WindowStateListener wsl) { windowStateListener = AWTEventMulticaster.add (windowStateListener, wsl); } /** * Removes the specified listener from this window. */ public void removeWindowFocusListener (WindowFocusListener wfl) { windowFocusListener = AWTEventMulticaster.remove (windowFocusListener, wfl); } /** * Removes the specified listener from this window. * * @since 1.4 */ public void removeWindowStateListener (WindowStateListener wsl) { windowStateListener = AWTEventMulticaster.remove (windowStateListener, wsl); } /** * Returns an array of all the objects currently registered as FooListeners * upon this Window. FooListeners are registered using the addFooListener * method. * * @exception ClassCastException If listenerType doesn't specify a class or * interface that implements java.util.EventListener. * * @since 1.3 */ public EventListener[] getListeners(Class listenerType) { if (listenerType == WindowListener.class) return getWindowListeners(); return super.getListeners(listenerType); } void dispatchEventImpl(AWTEvent e) { // Make use of event id's in order to avoid multiple instanceof tests. if (e.id <= WindowEvent.WINDOW_LAST && e.id >= WindowEvent.WINDOW_FIRST && (windowListener != null || windowFocusListener != null || windowStateListener != null || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0)) processEvent(e); else if (e.id == ComponentEvent.COMPONENT_RESIZED) validate (); else super.dispatchEventImpl(e); } /** * Processes the specified event for this window. If the event is an * instance of <code>WindowEvent</code>, then * <code>processWindowEvent()</code> is called to process the event, * otherwise the superclass version of this method is invoked. * * @param evt The event to process. */ protected void processEvent(AWTEvent evt) { if (evt instanceof WindowEvent) processWindowEvent((WindowEvent) evt); else super.processEvent(evt); } /** * Dispatches this event to any listeners that are listening for * <code>WindowEvents</code> on this window. This method only gets * invoked if it is enabled via <code>enableEvents()</code> or if * a listener has been added. * * @param evt The event to process. */ protected void processWindowEvent(WindowEvent evt) { int id = evt.getID(); if (id == WindowEvent.WINDOW_GAINED_FOCUS || id == WindowEvent.WINDOW_LOST_FOCUS) processWindowFocusEvent (evt); else if (id == WindowEvent.WINDOW_STATE_CHANGED) processWindowStateEvent (evt); else { if (windowListener != null) { switch (evt.getID()) { case WindowEvent.WINDOW_ACTIVATED: windowListener.windowActivated(evt); break; case WindowEvent.WINDOW_CLOSED: windowListener.windowClosed(evt); break; case WindowEvent.WINDOW_CLOSING: windowListener.windowClosing(evt); break; case WindowEvent.WINDOW_DEACTIVATED: windowListener.windowDeactivated(evt); break; case WindowEvent.WINDOW_DEICONIFIED: windowListener.windowDeiconified(evt); break; case WindowEvent.WINDOW_ICONIFIED: windowListener.windowIconified(evt); break; case WindowEvent.WINDOW_OPENED: windowListener.windowOpened(evt); break; default: break; } } } } /** * Identifies if this window is active. The active window is a Frame or * Dialog that has focus or owns the active window. * * @return true if active, else false. * @since 1.4 */ public boolean isActive() { KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); return manager.getActiveWindow() == this; } /** * Identifies if this window is focused. A window is focused if it is the * focus owner or it contains the focus owner. * * @return true if focused, else false. * @since 1.4 */ public boolean isFocused() { KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); return manager.getFocusedWindow() == this; } /** * Returns the child window that has focus if this window is active. * This method returns <code>null</code> if this window is not active * or no children have focus. * * @return The component that has focus, or <code>null</code> if no * component has focus. */ public Component getFocusOwner () { KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); Window activeWindow = manager.getActiveWindow (); // The currently-focused Component belongs to the active Window. if (activeWindow == this) return manager.getFocusOwner (); else return null; } /** * Returns the child component of this window that would receive * focus if this window were to become focused. If the window * already has the top-level focus, then this method returns the * same component as getFocusOwner. If no child component has * requested focus within the window, then the initial focus owner * is returned. If this is a non-focusable window, this method * returns null. * * @return the child component of this window that most recently had * the focus, or <code>null</code> * @since 1.4 */ public Component getMostRecentFocusOwner () { return windowFocusOwner; } /** * Set the focus owner for this window. This method is used to * remember which component was focused when this window lost * top-level focus, so that when it regains top-level focus the same * child component can be refocused. * * @param windowFocusOwner the component in this window that owns * the focus. */ void setFocusOwner (Component windowFocusOwner)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -