-- java.lang.IllegalArgumentException: adding container's parent to
itself
at java.awt.Container.add(Container.java:120)
at java.awt.Container.add(Container.java:102)
at ScrollPanel.add(Compiled Code)
at java.awt.Container.add(Container.java:161)
at ScrollPanel.<init>(Compiled Code)
at ScrollApplet.<init>(Compiled Code)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:386)
at sun.applet.AppletPanel.run(AppletPanel.java:204)
at java.lang.Thread.run(Thread.java)
------------------------------------------------------------------------
Here is the add() method
-----------------------------------------------------------------
public Component add( Component c)
{
Mypanel.add(c);
return c;
}
------------------------------------------------------
and in inherintg class I give
-=-----------------------
. .. . . .
add(new Button("hello");
------------
What is the mistake
thanks in advance
vijju
Have A Nice Time ......
--------------------------------------------------------
e-mail vi...@regal.india.hp.com
------------------------ ) (
A. B. Vijay Kumar // ~~~~~~~~~~ \\
Hewlett Packard ISO \\ / \ //
30c Cunningham Road \| O O |/
Bangalore 560 052 \ /
\ (o o) /
Phone 2251554 x 1466 \ ~~~~ /
----------------------------o0o--------------------o0o---
) ) )
---------------------------------------------------------
Container (which your Applet is an instance of) knows how to add
Components; you do not want to override add unless you want to change
how to add or what happens when one adds. This is basic OOP philosophy
stuff that I can't cover here, but consider reading up on OOP
techniques. On to specifics:
> I get the message
> ------------------------------------------------------------------------
>
> -- java.lang.IllegalArgumentException: adding container's parent to
> itself
> at java.awt.Container.add(Container.java:120)
> at java.awt.Container.add(Container.java:102)
> at ScrollPanel.add(Compiled Code)
> at java.awt.Container.add(Container.java:161)
> at ScrollPanel.<init>(Compiled Code)
> at ScrollApplet.<init>(Compiled Code)
> at sun.applet.AppletPanel.runLoader(AppletPanel.java:386)
> at sun.applet.AppletPanel.run(AppletPanel.java:204)
> at java.lang.Thread.run(Thread.java)
> ------------------------------------------------------------------------
>
> Here is the add() method
> -----------------------------------------------------------------
> public Component add( Component c)
> {
> Mypanel.add(c);
You get the message when you add Mypanel (you should use names
starting with upper case for classes and interfaces only, not for
variables; see a Java tutorial) to your applet. That invokes
this overridden add method, which tries to add Mypanel to itself.
Remove this add method altogether.
> return c;
> }
> ------------------------------------------------------
> and in inherintg class I give
> -=-----------------------
> . .. . . .
> add(new Button("hello");
Just use
myPanel.add(new Button("hello"));
(note "corrected" spelling of Mypanel)
or, with more proper OOP technique, add the Components of myPanel
in myPanel, not in the applet that contains it. This is best done
in the addNotify() method (that's a long story, covered in some of
my other postings), like so:
class myPanel
{
...
public void addNotify()
{
super.addNotify(); // don't forget this!!
add(new Button("hello"));
...
}
...
}
--
<J Q B>
> Here is the add() method
>-----------------------------------------------------------------
>public Component add( Component c)
>{
> Mypanel.add(c);
> return c;
>}
How do you add Mypanel to your applet?
If you are not doing:
super.add(Mypanel);
then you are probably trying to Mypanel.add(Mypanel) which isn't kosha.
Hope this helps.
Gordon
-- gordo...@antdiv.gov.au --- gordo...@acslink.net.au
Gordon Keith ,-_|\ Ph: +61 3 6232 3489
Programmer / \ Fax: +61 3 6232 3351
Marine Science Section \_,-._/
Australian Antarctic Division *
http://www.antdiv.gov.au http://acslink.net.au/~gordonkeith
(Standard disclaimer applies)
~!