setting a new layout

M

Matthijs Blaas

Hi all!

I have an applet(the loader applet) that adds another applet (the subapplet)
to itself. I want this subapplet to be able to draw to the screen, so i make
a new border layout for this subapplet. When I load the loader applet, it
loads the subapplet fine, it calls all methods from the subapplet (even the
paint method), but it draws nothing to the screen? Does anyone know what im
doing wrong here:

<snippet from the loader applet>
Class clas = Class.forName(Subapplet);
sub = (Applet)clas.newInstance();
sub.setStub(stub);
//sub.setLayout(getLayout()); doesn't seem to work correctly only draws a
very small square for subapplet
sub.setLayout(new BorderLayout());
add(sub, "CENTER");
//doLayout(); doesn't seem to do anything
//addNotify(); doesn't seem to do anything
sub.init();
sub.start();

Thanks in advance!

Matthijs Blaas
 
A

Andrew Thompson

I have an applet..

URL? Link to the source.

And while I am on the subject..
..(the loader applet) that adds another applet (the subapplet)
to itself. I want this subapplet to be able to draw to the screen, so i make
a new border layout for this subapplet.

What is the connection between BorderLayout
and wanting to draw?
....When I load the loader applet, it
loads the subapplet fine, it calls all methods from the subapplet (even the
paint method), but it draws nothing to the screen? Does anyone know what im
doing wrong here: .....
sub.setLayout(new BorderLayout());
add(sub, "CENTER");

Applet sub-classes Panel, which has a
default layout of FlowLayout, so while your
sub-applet has a BorderLayout, the parent
will still be FlowLayout.

If the subapplet returns a preferred size
of '0', that is what the FlowLayout will
give it.

(And if you respond that you set the
layout somewhere else, I am going to
get quite terse with you, harking back
to the URL and code link.)
 
M

Matthijs Blaas

URL? Link to the source.

I've uploaded the files to:
http://www.virtual-boy.org/applet/

Thanks, I'll check it out!
What is the connection between BorderLayout
and wanting to draw?

Well I've tried to use the same layout for the subapplet as the loader
applet uses (by doing: sub.setLayout(getLayout())) but that didn't do
anything good neither. So I thought I'd might need to set a new layout for
the subapplet...
If the subapplet returns a preferred size
of '0', that is what the FlowLayout will
give it.

I've tried to use setBounds for the sub applet, but I suppose thats not the
way to set the preffered size for the layout then?

Thanks for your time!

Thijs
 
A

Andrew Thompson


That is much more useful.
I've tried to use setBounds for the sub applet, but I suppose thats not the
way to set the preffered size for the layout then?

override getPreferredSize().

Now. General tips..

You caught a Throwable and used System.out.println(t);

It is much better to catch Exception and e.printStackTrace();

Your example could have been made better by
hardcoding.. Oh crap! I ended up making so
many little changes to it that it is easier
to give you back the altered source.

You can see the applet here..
<http://www.physci.org/test/001Loader/Loader.html>

But the altered source is a proprietary secret..






Just kidding, ..just kidding! ;-)
<http://www.physci.org/test/001Loader/>

Let me know once you have it and I will
delete the files.

HTH
 
M

Matthijs Blaas

Ok it works now, thanks a million!!
I also found out that I need to set the subapplet's size: sub.setSize(x,y)
in the loader besides overriding the getPrefferedSize in the subapplet,
because I work with images etc in the sub applet..

-Thijs
 
A

Andrew Thompson

Ok it works now, thanks a million!!

U welcome.

...actually I had been thinking of doing
something similar but hadn't the foggiest
idea where to begin. Your code solved
that, so, ..Thank You! ;-)

I'll take the files down now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top