📄 component.java
字号:
*/ public VolatileImage createVolatileImage(int width, int height) { if (GraphicsEnvironment.isHeadless()) return null; GraphicsConfiguration config = getGraphicsConfiguration(); return config == null ? null : config.createCompatibleVolatileImage(width, height); } /** * Creates an image with the specified width and height for use in * double buffering. Headless environments do not support images. The image * will support the specified capabilities. * * @param width the width of the image * @param height the height of the image * @param caps the requested capabilities * @return the requested image, or null if it is not supported * @throws AWTException if a buffer with the capabilities cannot be created * @since 1.4 */ public VolatileImage createVolatileImage(int width, int height, ImageCapabilities caps) throws AWTException { if (GraphicsEnvironment.isHeadless()) return null; GraphicsConfiguration config = getGraphicsConfiguration(); return config == null ? null : config.createCompatibleVolatileImage(width, height, caps); } /** * Prepares the specified image for rendering on this component. * * @param image the image to prepare for rendering * @param observer the observer to notify of image preparation status * @return true if the image is already fully prepared * @throws NullPointerException if image is null */ public boolean prepareImage(Image image, ImageObserver observer) { return prepareImage(image, image.getWidth(observer), image.getHeight(observer), observer); } /** * Prepares the specified image for rendering on this component at the * specified scaled width and height * * @param image the image to prepare for rendering * @param width the scaled width of the image * @param height the scaled height of the image * @param observer the observer to notify of image preparation status * @return true if the image is already fully prepared */ public boolean prepareImage(Image image, int width, int height, ImageObserver observer) { return peer.prepareImage(image, width, height, observer); } /** * Returns the status of the loading of the specified image. The value * returned will be those flags defined in <code>ImageObserver</code>. * * @param image the image to check on * @param observer the observer to notify of image loading progress * @return the image observer flags indicating the status of the load * @see #prepareImage(Image, int, int, ImageObserver) * @see #Toolkit#checkImage(Image, int, int, ImageObserver) * @throws NullPointerException if image is null */ public int checkImage(Image image, ImageObserver observer) { return checkImage(image, image.getWidth(observer), image.getHeight(observer), observer); } /** * Returns the status of the loading of the specified image. The value * returned will be those flags defined in <code>ImageObserver</code>. * * @param image the image to check on * @param width the scaled image width * @param height the scaled image height * @param observer the observer to notify of image loading progress * @return the image observer flags indicating the status of the load * @see #prepareImage(Image, int, int, ImageObserver) * @see #Toolkit#checkImage(Image, int, int, ImageObserver) */ public int checkImage(Image image, int width, int height, ImageObserver observer) { if (peer != null) return peer.checkImage(image, width, height, observer); return getToolkit().checkImage(image, width, height, observer); } /** * Sets whether paint messages delivered by the operating system should be * ignored. This does not affect messages from AWT, except for those * triggered by OS messages. Setting this to true can allow faster * performance in full-screen mode or page-flipping. * * @param ignoreRepaint the new setting for ignoring repaint events * @see #getIgnoreRepaint() * @see BufferStrategy * @see GraphicsDevice.setFullScreenWindow(Window) * @since 1.4 */ public void setIgnoreRepaint(boolean ignoreRepaint) { this.ignoreRepaint = ignoreRepaint; } /** * Test whether paint events from the operating system are ignored. * * @return the status of ignoring paint events * @see #setIgnoreRepaint(boolean) * @since 1.4 */ public boolean getIgnoreRepaint() { return ignoreRepaint; } /** * Tests whether or not the specified point is contained within this * component. Coordinates are relative to this component. * * @param x the X coordinate of the point to test * @param y the Y coordinate of the point to test * @return true if the point is within this component * @see #getComponentAt(int, int) */ public boolean contains(int x, int y) { return x >= 0 && y >= 0 && x < width && y < height; } /** * Tests whether or not the specified point is contained within this * component. Coordinates are relative to this component. * * @param x the X coordinate of the point to test * @param y the Y coordinate of the point to test * @return true if the point is within this component * @deprecated use {@link #contains(int, int)} instead */ public boolean inside(int x, int y) { return contains(x, y); } /** * Tests whether or not the specified point is contained within this * component. Coordinates are relative to this component. * * @param p the point to test * @return true if the point is within this component * @throws NullPointerException if p is null * @see #getComponentAt(Point) * @since 1.1 */ public boolean contains(Point p) { return contains(p.x, p.y); } /** * Returns the component occupying the position (x,y). This will either * be this component, an immediate child component, or <code>null</code> * if neither of the first two occupies the specified location. * * @param x the X coordinate to search for components at * @param y the Y coordinate to search for components at * @return the component at the specified location, or null * @see #contains(int, int) */ public Component getComponentAt(int x, int y) { return contains(x, y) ? this : null; } /** * Returns the component occupying the position (x,y). This will either * be this component, an immediate child component, or <code>null</code> * if neither of the first two occupies the specified location. * * @param x the X coordinate to search for components at * @param y the Y coordinate to search for components at * @return the component at the specified location, or null * @deprecated use {@link #getComponentAt(int, int)} instead */ public Component locate(int x, int y) { return getComponentAt(x, y); } /** * Returns the component occupying the position (x,y). This will either * be this component, an immediate child component, or <code>null</code> * if neither of the first two occupies the specified location. * * @param p the point to search for components at * @return the component at the specified location, or null * @throws NullPointerException if p is null * @see #contains(Point) * @since 1.1 */ public Component getComponentAt(Point p) { return getComponentAt(p.x, p.y); } /** * AWT 1.0 event dispatcher. * * @param e the event to dispatch * @deprecated use {@link #dispatchEvent(AWTEvent)} instead */ public void deliverEvent(Event e) { // XXX Add backward compatibility handling. } /** * Forwards AWT events to processEvent() if:<ul> * <li>Events have been enabled for this type of event via * <code>enableEvents()</code></li>, * <li>There is at least one registered listener for this type of event</li> * </ul> * * @param e the event to dispatch */ public final void dispatchEvent(AWTEvent e) { // Some subclasses in the AWT package need to override this behavior, // hence the use of dispatchEventImpl(). dispatchEventImpl(e); if (peer != null && ! e.consumed) peer.handleEvent(e); } /** * AWT 1.0 event dispatcher. * * @param e the event to dispatch * @return false: since the method was deprecated, the return has no meaning * @deprecated use {@link #dispatchEvent(AWTEvent)} instead */ public boolean postEvent(Event e) { // XXX Add backward compatibility handling. return false; } /** * Adds the specified listener to this component. This is harmless if the * listener is null, but if the listener has already been registered, it * will now be registered twice. * * @param listener the new listener to add * @see ComponentEvent * @see #removeComponentListener(ComponentListener) * @see #getComponentListeners() * @since 1.1 */ public synchronized void addComponentListener(ComponentListener l) { componentListener = AWTEventMulticaster.add(componentListener, l); if (componentListener != null) enableEvents(AWTEvent.COMPONENT_EVENT_MASK); } /** * Removes the specified listener from the component. This is harmless if * the listener was not previously registered. * * @param listener the listener to remove * @see ComponentEvent * @see #addComponentListener(ComponentListener) * @see #getComponentListeners() * @since 1.1 */ public synchronized void removeComponentListener(ComponentListener l) { componentListener = AWTEventMulticaster.remove(componentListener, l); } /** * Returns an array of all specified listeners registered on this component. * * @return an array of listeners * @see #addComponentListener(ComponentListener) * @see #removeComponentListener(ComponentListener) * @since 1.4 */ public synchronized ComponentListener[] getComponentListeners() { return (ComponentListener[]) AWTEventMulticaster.getListeners(componentListener, ComponentListener.class); } /** * Adds the specified listener to this component. This is harmless if the * listener is null, but if the listener has already been registered, it * will now be registered twice. * * @param listener the new listener to add * @see FocusEvent * @see #removeFocusListener(FocusListener) * @see #getFocusListeners() * @since 1.1 */ public synchronized void addFocusListener(FocusListener l) { focusListener = AWTEventMulticaster.add(focusListener, l); if (focusListener != null) enableEvents(AWTEvent.FOCUS_EVENT_MASK); } /** * Removes the specified listener from the component. This is harmless if * the listener was not previously registered. * * @param listener the listener to remove * @see FocusEvent * @see #addFocusListener(FocusListener) * @see #getFocusListeners() * @since 1.1 */ public synchronized void removeFocusListener(FocusListener l) { focusListener = AWTEventMulticaster.remove(focusListener, l); } /** * Returns an array of all specified listeners registered on this component. * * @return an array of listeners * @see #addFocusListener(FocusListener) * @see #removeFocusListener(FocusListener) * @since 1.4 */ public synchronized FocusListener[] getFocusListeners() { return (FocusListener[]) AWTEventMulticaster.getListeners(focusListener, FocusListener.class); } /** * Adds the specified listener to this component. This is harmless if the * listener is null, but if the listener has already been registered, it * will now be registered twice. * * @param listener the new listener to add * @see HierarchyEvent * @see #removeHierarchyListener(HierarchyListener) * @see #getHierarchyListeners() * @since 1.3 */ public synchronized void addHierarchyListener(HierarchyListener l) { hierarchyListener = AWTEventMulticaster.add(hierarchyListener, l); if (hierarchyListener != null) enableEvents(AWTEvent.HIERARCHY_EVENT_MASK); } /** * Removes the specified listener from the component. This is harmless if * the listener was not previously registered. * * @param listener the listener to remove * @see HierarchyEvent * @see #addHierarchyListener(HierarchyListener) * @see #getHierarchyListeners() * @since 1.3 */ public synchronized void removeHierarchyListener(HierarchyListener l) { hierarchyListener = AWTEventMulticaster.remove(hierarchyListener, l); } /** * Returns an array of all specified listeners registered on this component. * * @return an array of listeners * @see #addHierarchyListener(HierarchyListener) * @see #removeHierarchyListener(HierarchyListener) * @since 1.4 */ public synchronized HierarchyListener[] getHierarchyListeners() { return (HierarchyListener[]) AWTEventMulticaster.getListeners(hierarchyListener, HierarchyListener.class); } /** * Adds the specified listener to this component. This is harmless if the * listener is null, but if the listener has already been registered, it * will now be registered twice. * * @param listener the new listener to add * @see HierarchyEvent * @see #removeHierarchyBoundsListener(HierarchyBoundsListener) * @see #getHierarchyBoundsListeners() * @since 1.3 */ public synchronized void addHierarchyBoundsListener(HierarchyBoundsListener l) { hierarchyBoundsListener = AWTEventMulticaster.add(hierarchyBoundsListener, l); if (hierarchyBoundsListener != null) enableEvents(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK); } /** * Removes the specified listener from the component. This is harmless if * the listener was not previously registered. * * @param listener the listener to remove * @see HierarchyEvent * @see #addHierarchyBoundsListener(HierarchyBoundsListener) * @see #getHierarchyBoundsListeners() * @since 1.3 */ public synchronized void removeHierarchyBoundsListener(HierarchyBoundsListener l) { hierarchyBoundsListener = AWTEventMulticaster.remove(hierarchyBoundsListener, l); } /** * Returns an array of all specified listeners registered on this component. * * @return an array of listeners * @see #addHierarchyBoundsListener(HierarchyBoundsListener) * @see #removeHierarchyBoundsListener(HierarchyBoundsListener) * @since 1.4 */ public synchronized HierarchyBoundsListener[] getHierarchyBoundsListeners() { return (HierarchyBoundsListener[]) AWTEventMulticaster.getListeners(hierarchyBoundsListener, HierarchyBoundsListener.class); } /** * Adds the specified listener to this component. This is harmless if the * listener is null, but if the listener has already been registered, it * will now be registered twice. * * @param listener the new listener to add * @see KeyEvent * @see #removeKeyListener(KeyListener) * @see #getKeyListeners() * @since 1.1 */ public synchronized void addKeyL
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -