Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

what does "addNotify" really do ???

Posted on 1997-10-23
1
294 Views
Last Modified: 2008-02-26
Hi,

Can someone explain to me what does the "addNotify()" command do
in Panel (or Applet).

I have a problem in NT platforms. My applet does not refresh an
 inner layed canvas. The same applet works fine on Unix and Win95
 platforms.

 Only when i added "addNotify()" to the applet start()
  it solved the refresh problem.
 But, to my poor luck it caused a SEGMENTATION FAULT(!) both in the
 Unix appletviewer and Netscape 3.0.

thanks,
Avi Kavas.
0
Comment
Question by:kavas
1 Comment
 
LVL 3

Accepted Solution

by:
gwalters earned 50 total points
ID: 1229477
The addNotify() method creates a peer for the given component.  A peer is a class which is responsible for the appearance of that component (where the component itself is responsible for its functionality).  Peers are usually (but don't have to be) native code.  It's really just a way of separating function from appearance (so a TextField, for example, functions the same on Unix and Windows, but it's appearance is platform-dependant).

Here is the addNotify() method from the Panel class:

public syncronized void addNotify() {
  peer = getToolkit().createPanel(this);
  super.addNotify();
}

You should never have to call addNotify() directly.  The fact that it fixed your problem is most likely a coincidence.  However, I can't imagine that calling it would cause SEGMENTATION FAULT.

One thing is that, if the start method never returns, the applet will never be shown.  This is because the browser calls start() and then show() on the applet.  It's a good idea to only do simple setup in the start() method and return.  If you really need a running thread for the life of your applet (most really don't: they just process events), then you can implement Runnable, and put all that code in the run() method.

Or you can call show() yourself, but it's still not a good idea to stay in start() indefinitely.

Sorry for the rambling!


0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question