1. javax.swing.JFrame
1.1 JFrame 的层次结构
- Class JFrame
- java.lang.Object
- java.awt.Component
- java.awt.Container
- java.awt.Window
- java.awt.Frame
- javax.swing.JFrame
- java.awt.Frame
- java.awt.Window
- java.awt.Container
- java.awt.Component
- java.lang.Object
在java api 8 中对Class JFrame是这样描述的:
java.awt.frame的扩展版本,它为JFC / Swing组件架构添加了支持。
Warning: Swing is not thread safe. For more information see Swing’s Threading Policy. Swing不是线程安全的。
1.2 JFrame中的 Nested Classes (内部类)
- JFrame.AccessibleJFrame
此类实现JFrame类的可访问性支持。
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 实现了awt中的AccessibleAWTFrame接口
此类实现窗口类的辅助功能支持。
它提供适合窗口用户界面元素的Java可访问性API的实现。
- public String getAccessibleName() 对象的本地化名称,可以为空
Component 接口的实现方法
实现逻辑是首先获取 accessibleName 不为空则返回accessibleName,否则获取窗体的title ,title为空则拿父类的accessibleName ,否则返回title
- public AccessibleStateSet getAccessibleStateSet() 获取当前对象的状态 覆写了父类awt中Fram的方法
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;
}
逻辑:父类对象调用拿到窗口状态对象引用,获取表示此窗口是否可供用户调整,是则添加一个AccessibleState.RESIZABLE表示当前窗口不是固定的。获取该窗口有焦点,有则返回该窗口的子组件对象不为空时添加为AccessibleState.ACTIVE表示当前窗口为活动窗口。
1.3 JFram中的Fields (属性域)
- protected AccessibleContextaccessibleContext 可访问的上下文属性。
- static int EXIT_ON_CLOSE 退出应用程序默认窗口关闭操作。
- protected JRootPane rootPane管 理ContentPane和此窗口的可选菜单中的JrootPane实例以及Glasspane。
- protected boolean rootPaneCheckingEnabled 如果true,则将添加和setLayout调用将转发到ContentPane。
contentPane
swing中的四大重量级组件 JFrame, JDialog, JWindow, and JApplet
JROOTPANE使用的自定义布局管理器可确保:
Glasspane填充了jrootpane的整个可视区域(边界 - 插孔)。
DiallayPane填充了Jrootpane的整个可视区域。
(边界 - 插入)
培养箱位于层盖的上边缘。
ContentPane填充整个可视区域,如果存在,减去菜单栏。
1.4 JFram Constructors (构造器)
- JFrame() 初始无参构造器
- JFrame(GraphicsConfiguration gc) 在屏幕设备的指定图形配置和空白标题中创建窗体
- JFrame(String title) 创建一个具有指定标题的新初始隐形窗体
- JFrame(String title, GraphicsConfiguration gc) 使用指定的标题和屏幕设备的指定图形配置创建JFrame。
1.5 JFram Method Summary (只描述常用方法)
- 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);
}
}
在时间毫秒内重新粉刷此组件的指定矩形。
time : 更新前的最长时间以毫秒为单位
x,y坐标、宽度和高度