Solved

what does "addNotify" really do ???

Posted on 1997-10-23
1
267 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

762 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

6 Experts available now in Live!

Get 1:1 Help Now