问题描述
我试图找到 addNotify()
的外行定义,但我无法使用Google获得任何答案。
I've tried to find a laymans definition of addNotify()
but I can't really get any answer using Google.
据我所知,在我的课程中覆盖 addNotify()
时,我应该调用 super.addNotify();
然后再做其他事情。
As far as I know, when overriding addNotify()
in my class, I should call super.addNotify();
and then do whatever else afterward.
我的问题是, addNotify()
会自动运行吗?它是什么目的以及当我覆盖它时会发生什么?此外,为什么我要覆盖这个方法?
My question is, does addNotify()
run automatically? What is it's purpose and what happens when I override it and furthermore, why would I ever want to override this method?
谢谢。
推荐答案
是的。准确的位置和时间取决于AWT实施的内部。
Yes. The precise where and when depends on the internals of the AWT implementation.
如。它是非常低级别的东西,是将AWT世界连接到本地窗口世界的胶水的一部分。 (我故意是高级和模糊的。如果你想要了解细节,请下载并阅读OpenJDK源代码。)
It is as described in the javadoc. It is very low level stuff that is part of the "glue" that connects the AWT world to the native windowing world. (I'm being deliberately high-level and vague. If you want the nitty-gritty details, download and read the OpenJDK source code.)
你可能会打破AWT: - )
You'd probably break AWT :-)
I想不出这样做的好理由......除非你试图将AWT移植到不同的操作系统或不同的本机窗口系统。
I can't think of a good reason to do this ... unless you were trying to port AWT to a different operating system or a different native windowing system.
这篇关于什么是addNotify();?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!