当前位置:网站首页>Why can swing implement a form program by inheriting the JFrame class?

Why can swing implement a form program by inheriting the JFrame class?

2022-07-06 14:43:00 in a cocoon around oneself.

1. javax.swing.JFrame

1.1 JFrame Hierarchical structure

  • Class JFrame
    • java.lang.Object
      • java.awt.Component
        • java.awt.Container
          • java.awt.Window
            • java.awt.Frame
              • javax.swing.JFrame

stay java api 8 Chinese vs Class JFrame It's described like this :
java.awt.frame Extended version of , It's for JFC / Swing Component architecture adds support .
Warning: Swing is not thread safe. For more information see Swing’s Threading Policy. Swing Not thread safe .

1.2 JFrame Medium Nested Classes ( Inner class )

  • JFrame.AccessibleJFrame

This kind of implementation JFrame Class accessibility support .

 protected class AccessibleJFrame extends AccessibleAWTFrame {
    

        // AccessibleContext methods
        /** * Get the accessible name of this object. * * @return the localized name of the object -- can be null if this * object does not have a name */
        public String getAccessibleName() {
    
            if (accessibleName != null) {
    
                return accessibleName;
            } else {
    
                if (getTitle() == null) {
    
                    return super.getAccessibleName();
                } else {
    
                    return getTitle();
                }
            }
        }

        /** * Get the state of this object. * * @return an instance of AccessibleStateSet containing the current * state set of the object * @see AccessibleState */
        public AccessibleStateSet getAccessibleStateSet() {
    
            AccessibleStateSet states = super.getAccessibleStateSet();

            if (isResizable()) {
    
                states.add(AccessibleState.RESIZABLE);
            }
            if (getFocusOwner() != null) {
    
                states.add(AccessibleState.ACTIVE);
            }
            // FIXME: [[[WDW - should also return ICONIFIED and ICONIFIABLE
            // if we can ever figure these out]]]
            return states;
        }
    } // inner class AccessibleJFrame

AccessibleJFrame Realized awt Medium AccessibleAWTFrame Interface
This class implements the auxiliary function support of the window class .
It provides... Suitable for window user interface elements Java Accessibility API The implementation of the .

  • public String getAccessibleName() Localized name of the object , Can be null
    Component How to implement the interface

The implementation logic is to get accessibleName If it is not empty, return accessibleName, Otherwise, get the form title ,title If it is empty, take the parent class accessibleName , Otherwise return to title

  • public AccessibleStateSet getAccessibleStateSet() Get the status of the current object Overriding the parent class awt in Fram Methods
   public AccessibleStateSet getAccessibleStateSet() {
    
            AccessibleStateSet states = super.getAccessibleStateSet();

            if (isResizable()) {
    
                states.add(AccessibleState.RESIZABLE);
            }
            if (getFocusOwner() != null) {
    
                states.add(AccessibleState.ACTIVE);
            }
            // FIXME: [[[WDW - should also return ICONIFIED and ICONIFIABLE
            // if we can ever figure these out]]]
            return states;
        }

Logic : The parent object call gets the window state object reference , Gets whether this window is available for user adjustment , If yes, add one AccessibleState.RESIZABLE Indicates that the current window is not fixed . Get that the window has focus , If yes, it will be added as AccessibleState.ACTIVE Indicates that the current window is active .

1.3 JFram Medium Fields ( Property fields )

  • protected AccessibleContextaccessibleContext Accessible context properties .
  • static int EXIT_ON_CLOSE Exit the default window closing operation of the application .
  • protected JRootPane rootPane tube The reason is ContentPane And... In the optional menu of this window JrootPane Examples and Glasspane.
  • protected boolean rootPaneCheckingEnabled If true, Will add and setLayout The call will be forwarded to ContentPane.

contentPane

swing Four heavyweight components in JFrame, JDialog, JWindow, and JApplet swing Four heavyweight components in
swing Four heavyweight component structures in
JROOTPANE The custom layout manager used ensures :
Glasspane Filled jrootpane The entire visible area of ( The border - Jack ).
DiallayPane Filled Jrootpane The entire visible area of .
( The border - Insert )
The incubator is located on the upper edge of the cover .
ContentPane Fill the entire visible area , If there is , Subtract the menu bar .

1.4 JFram Constructors ( Constructors )

  • JFrame() Initial parameterless constructor
  • JFrame(GraphicsConfiguration gc) Create a form in the specified graphic configuration and blank title of the screen device
  • JFrame(String title) Create a new initial invisible form with the specified title
  • JFrame(String title, GraphicsConfiguration gc) Create with the specified title and the specified graphic configuration of the screen device JFrame.

1.5 JFram Method Summary ( Only describe common methods )

  • public void repaint(long time,
    int x,
    int y,
    int width,
    int height)
 public void repaint(long time, int x, int y, int width, int height) {
    
        if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) {
    
            RepaintManager.currentManager(this).addDirtyRegion(
                              this, x, y, width, height);
        }
        else {
    
            super.repaint(time, x, y, width, height);
        }
    }

Repaint the specified rectangle of this component in milliseconds .
time : The maximum time before updating is in milliseconds
x,y coordinate 、 Width and height

原网站

版权声明
本文为[in a cocoon around oneself.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131351341747.html