Solved

what does "addNotify" really do ???

Posted on 1997-10-23
1
276 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java and GPO 11 68
Error with Java/Cache JDBC Classpath 2 30
netstat -ano | find "8000" and taskkill /f /pid 2984 3 30
Apps blocked by Java 9 59
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

914 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now