📄 window.java
字号:
* as undisplayable. * <p> * The Window and its subcomponents can be made displayable again * by rebuilding the native resources with a subsequent call to * <code>pack</code> or <code>show</code>. 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). * </p> * @see Component#isDisplayable * @see Window#pack * @see Window#show */ public void dispose() { setVisible(false); removeNotify(); Toolkit.getEventQueue().postEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSED)); //SunToolkit.postEvent(appContext, new WindowEvent(this, WindowEvent.WINDOW_CLOSED)); /* IM cleanup currently as Window.dispose() is not called for *if (inputContext != null) { * InputContext toDispose = inputContext; * inputContext = null; * toDispose.dispose(); *} */ } public void update(Graphics g) { if (isShowing()) { g.clearRect(0, 0, width, height); paint(g); } } /** * 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 java.awt.Window#toBack */ public void toFront() {} /** * 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 java.awt.Window#toFront */ public void toBack() {} /** * 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 <code>checkTopLevelWindow</code> method returns * <code>false</code> when this window is passed to it as an * argument. * <p> * If the window is secure, then <code>getWarningString</code> * returns <code>null</code>. If the window is insecure, this * method checks for the system property * <code>awt.appletWarning</code> * and returns the string value of that property. * @return the warning string for this window. * @see java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object) */ public final String getWarningString() { return warningString; } /** 6221221 */ private void setWarningString() { warningString = null; SecurityManager sm = System.getSecurityManager(); if (sm != null) { if (!sm.checkTopLevelWindow(this)) { // make sure the privileged action is only // for getting the property! We don't want the // above checkTopLevelWindow call to always succeed! warningString = (String) AccessController.doPrivileged( new GetPropertyAction("awt.appletWarning", "Java Applet Window")); } } } /** * 6221221 * * Sets the warning string label and returns the height * of the label. The label height must be taken into * account when calculating the insets. */ private void setWarningString(String warningString) { warningLabelHeight = pSetWarningString(warningString); } /** * Determines the insets of this window, which indicate the size * of the window's border. * <p> * A <code>Frame</code> object, for example, has a top inset that * corresponds to the height of the frame's title bar. * @return the insets of this window. * @see java.awt.Insets * @see java.awt.LayoutManager * @since JDK1.1 */ public Insets getInsets() { //6221221 return new Insets(0, 0, 0, 0); return new Insets(0, 0, warningLabelHeight, 0); //6221221 } /** * Gets the <code>Locale</code> 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. * @return the locale that is set for this window. * @see java.util.Locale * @since JDK1.1 */ public Locale getLocale() { if (locale == null) return Locale.getDefault(); return locale; } /** * 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. * @see Component#getInputContext */ public synchronized InputContext getInputContext() { if (inputContext == null) { inputContext = InputContext.getInstance(); } return inputContext; } /** * Set the cursor image to a specified cursor. * @param <code>cursor</code> One of the constants defined * by the <code>Cursor</code> class. If this parameter is null * then the cursor for this window will be set to the type * Cursor.DEFAULT_CURSOR. * @see java.awt.Component#getCursor * @see java.awt.Cursor * @since JDK1.1 */ public void setCursor(Cursor cursor) { if (cursor == null) { cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); } super.setCursor(cursor); } public void setBackground(Color c) { Color oldBackground = background; background = c; if (c != null && !c.equals(oldBackground)) { // Normally a Window is a heavyweight component that paints its own // background and is opaque. Setting the background on a heavywieghht causes // the background to be updated immediately (on lightweight components the background is not // repainted until repaint is called). It is necessary to post a paint event // here to ensure that the background is repainted. We can't just call repaint because // the update method may be overridden so as to not paint the background. postPaintEvent(); } } /** Posts a paint event to the event queue for this window. This method should be called whenever a paint event would traditionally be generated by a heavyweight window. */ private void postPaintEvent() { //Toolkit.getEventQueue().postEvent(new PaintEvent(this, PaintEvent.PAINT, new Rectangle(0, 0, width, height))); SunToolkit.postEvent(appContext, new PaintEvent(this, PaintEvent.PAINT, new Rectangle(0, 0, width, height))); } /** * 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. * * @param l the window listener */ public synchronized void addWindowListener(WindowListener l) { if (l == null) { return; } windowListener = AWTEventMulticaster.add(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. * * @param l the window listener */ public synchronized void removeWindowListener(WindowListener l) { if (l == null) { return; } windowListener = AWTEventMulticaster.remove(windowListener, l); } /** * Returns an array of all the window listeners * registered on this window. * * @return all of this window's <code>WindowListener</code>s * or an empty array if no window * listeners are currently registered * * @see #addWindowListener * @see #removeWindowListener * @since 1.4 */ public synchronized WindowListener[] getWindowListeners() { return (WindowListener[]) AWTEventMulticaster.getListeners( (EventListener)windowListener, WindowListener.class); } boolean eventEnabled(AWTEvent e) { switch(e.id) { case WindowEvent.WINDOW_OPENED: case WindowEvent.WINDOW_CLOSING: case WindowEvent.WINDOW_CLOSED: case WindowEvent.WINDOW_ICONIFIED: case WindowEvent.WINDOW_DEICONIFIED: case WindowEvent.WINDOW_ACTIVATED: case WindowEvent.WINDOW_DEACTIVATED: if ((eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0 || windowListener != null) { return true; } return false; case WindowEvent.WINDOW_GAINED_FOCUS: case WindowEvent.WINDOW_LOST_FOCUS: if ((eventMask & AWTEvent.WINDOW_FOCUS_EVENT_MASK) != 0 || windowFocusListener != null) { return true; } return false; default: break; } return super.eventEnabled(e); } /** * Processes events on this window. If the event is an WindowEvent, * it invokes the processWindowEvent method, else it invokes its * superclass's processEvent. * @param e the event */ protected void processEvent(AWTEvent e) { if (e instanceof WindowEvent) { switch (e.getID()) { case WindowEvent.WINDOW_OPENED: case WindowEvent.WINDOW_CLOSING: case WindowEvent.WINDOW_CLOSED: case WindowEvent.WINDOW_ICONIFIED: case WindowEvent.WINDOW_DEICONIFIED: case WindowEvent.WINDOW_ACTIVATED: case WindowEvent.WINDOW_DEACTIVATED: processWindowEvent((WindowEvent)e); break; case WindowEvent.WINDOW_GAINED_FOCUS: case WindowEvent.WINDOW_LOST_FOCUS: processWindowFocusEvent((WindowEvent)e); break; default: break; } return; } super.processEvent(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() * @see Component#enableEvents * @param e the window event */ protected void processWindowEvent(WindowEvent e) { if (windowListener != null) { switch (e.getID()) { case WindowEvent.WINDOW_OPENED: windowListener.windowOpened(e); break; case WindowEvent.WINDOW_CLOSING: windowListener.windowClosing(e); break; case WindowEvent.WINDOW_CLOSED: windowListener.windowClosed(e); break; case WindowEvent.WINDOW_ICONIFIED: windowListener.windowIconified(e); break; case WindowEvent.WINDOW_DEICONIFIED: windowListener.windowDeiconified(e); break; case WindowEvent.WINDOW_ACTIVATED: windowListener.windowActivated(e); break; case WindowEvent.WINDOW_DEACTIVATED: windowListener.windowDeactivated(e); break; default: break; } } } /** Posts a mouse button event to the event queue for this window. This method will determine the click count for the event. It will also post a mouse click event if the mouse was released at the last click coordinate. This is called from native code when a mouse event is received. It could also be called from Robot implementations if it is not possible to generate mouse events at the native level (that is why it has been made package protected and not private). @param button the number of the button that was pressed or released (MouseEvent.BUTTON1, MouseEvent.BUTTON2, or MouseEvent.BUTTON3) @paran id either MouseEvent.MOUSE_PRESSED or MouseEvent.MOUSE_RELEASED @param modifiers the modifiers for the event (these are defined using the extended modifiers in InputEvent) @param x the x coordinate for the event @param y the y coordinate for the event */ void postMouseButtonEvent(int button, int id, int modifiers, int x, int y) { long when = System.currentTimeMillis(); if (id == MouseEvent.MOUSE_PRESSED) { if (x == lastClickX && y == lastClickY && when - lastClickTime <= 200) clickCount++; else clickCount = 1; lastClickX = x; lastClickY = y; lastClickButton = button; } boolean popupTrigger = id == MouseEvent.MOUSE_PRESSED && button == InputEvent.BUTTON3_MASK; //Toolkit.getEventQueue().postEvent(new MouseEvent (this, id, when, modifiers, x, y, clickCount, popupTrigger)); SunToolkit.postEvent(appContext, new MouseEvent (this, id, when, modifiers, x, y, clickCount, popupTrigger)); if (id == MouseEvent.MOUSE_RELEASED && lastClickX == x && lastClickY == y &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -