例如:有3个JFrame ,分别是 A,B,C。
A 中 构造出 B,B 中构造出 C 。
在A中实现一个“析构函数”,执行时可以把 B 和 C 上所有的资源都释放掉!
注意:B,C上可能还有其他的构件,例如一些按钮,线程等。。。
这些东西也要一起释放!!
问题:这个“析构函数”要如何实现,最好能是其他JFrame通用的!
...全文
66420打赏收藏
如何在JAVA中实现“析构函数”!!(急,高分)
例如:有3个JFrame ,分别是 A,B,C。 A 中 构造出 B,B 中构造出 C 。 在A中实现一个“析构函数”,执行时可以把 B 和 C 上所有的资源都释放掉! 注意:B,C上可能还有其他的构件,例如一些按钮,线程等。。。 这些东西也要一起释放!! 问题:这个“析构函数”要如何实现,最好能是其他JFrame通用的!
下面是Window的dispose()的解释:
---------------------------------
Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.
The Window and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack or show. 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 modifications between those actions).
-------------------------------------