对第二个问题我是根据swing的JFrame参考的。 我仔细看了一下awt的Frame, awt的关闭窗口确实没有直接起作用。在源代码里这样一句话. If the program doesn't explicitly hide or dispose the window while processing this event, the window close operation is canceled.事件触发源于Component的事件处理.实现代码是这一段: public synchronized void setState(int state) { int current = getExtendedState(); if (state == ICONIFIED && (current & ICONIFIED) == 0) { setExtendedState(current | ICONIFIED); } else if (state == NORMAL && (current & ICONIFIED) != 0) { setExtendedState(current & ~ICONIFIED); } }
答:Frame类已经加了这些处理事件
2,但是不写关闭事件代码的话,窗口不会自动关闭呢?
答:会关闭,但只是窗口消失,进程还在。
我仔细看了一下awt的Frame, awt的关闭窗口确实没有直接起作用。在源代码里这样一句话.
If the program doesn't explicitly hide or dispose the window while processing this event, the window close operation is canceled.事件触发源于Component的事件处理.实现代码是这一段:
public synchronized void setState(int state) {
int current = getExtendedState();
if (state == ICONIFIED && (current & ICONIFIED) == 0) {
setExtendedState(current | ICONIFIED);
}
else if (state == NORMAL && (current & ICONIFIED) != 0) {
setExtendedState(current & ~ICONIFIED);
}
}
关键是你要继承一个windowListener借口
它定义了6各方法,分别处理最大化,最小化,或的焦点,失去焦点,closing(),open()等,你可以自己查一下