gpt4 book ai didi

java - JFrame 被处置后的值(value)是多少?

转载 作者:行者123 更新时间:2023-11-30 08:00:25 25 4
gpt4 key购买 nike

该值不一定为 null(我认为?),因为它仍然是一个有效的引用。

最佳答案

JFrame 是一个对象,因此永远不能为 null,而 JFrame 变量可以引用有效的 JFrame 对象或没有引用,因此“为 null”。如果您在 JFrame 对象上调用 dispose(),该对象仍然存在,因此该变量不为空。然而,JFrame 释放了一些系统资源。如果重新渲染JFrame 对象,这些资源将再次获得。

通常情况下,对此类问题的最佳测试是 1) 创建并运行测试代码以及​​ 2) 检查 API

例如,

JFrame frame = new JFrame("Foo");
frame.pack();
frame.setVisible(true);

// in some listener
frame.dispose(); // it's no longer visible
System.out.println("is frame null? " + (frame == null));

根据 Window API,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).

关于java - JFrame 被处置后的值(value)是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38505068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com