What is addNotify ();?

I tried to find the definition of laymans addNotify() , but I can not get any answer using Google.

As far as I know, when overriding addNotify() in my class, I should call super.addNotify(); and then do something else after that.

My question is: is addNotify() executed automatically? What is this purpose and what happens when I redefine it and, moreover, why would I ever want to redefine this method?

Thank x.

+4
source share
3 answers

My question is, does addNotify () run automatically?

Yes. Exact where and when it depends on the internal components of the AWT implementation.

What is this goal

This is as described in javadoc . This is a very low-level material that is part of the “glue” that connects the AWT world to the native world of windows. (I am intentionally high-level and vague. If you want detailed details, download and read the OpenJDK source code.)

and what happens when I redefine it

You probably violate AWT :-)

and besides, why don't I want to override this method?

I cannot come up with a good reason for this ... unless you are trying to connect AWT to another operating system or another native windows system.

+3
source

Component # addNotify () is a method in the java.awt.Component class. The purpose of this method, as stated in the API:

Displays this component by connecting it to its own resource screen. This method is called an internal toolkit and should not be called directly by programs.

+1
source

The addNotify() / removeNotify() methods are the only hooks that AWT provides in which we can correctly destroy and recreate the OpenGL context, given that the main widget is to be destroyed. addNotify() used by low-level components to interact with the main partner in the operating system, so that something REALLY happens, and not just beautiful pictures on the screen.
It is better to avoid using this method.

+1
source

All Articles