Please...Applet frame resize problem

K

Kevin

It should be real easy but I'm having troubles.

I can't seem to get this darn frame to resize (or setsize) when the applet
is launched. All I get is a little frame window which I can then maximize
and see my applet. I think I have tried ever possible combination of the
Frame methods.

Could someone please lend a helping hand please don't make me beg.
Here is my watered down code.

import java.awt.*;

public class test extends java.applet.Applet {
Image currentimg;
Graphics currentGraphics;
Frame myframe;
static Dimension d;


public void init() {
myframe = new Frame("Test Applet");
d = Toolkit.getDefaultToolkit().getScreenSize();
myframe.add(this);
myframe.setSize(d.width, d.height);
myframe.setVisible(true);
myframe.pack();
myframe.show();
currentGraphics = getGraphics();
paint(currentGraphics);
}

public void run() {
}

public void update(Graphics g) {
paint(g);
}

public void paint(Graphics g) {
g.drawString("hello world",10,20);
}
}
 
A

Andrew Thompson

Kevin said:
It should be real easy but I'm having troubles.

I can't seem to get this darn frame to resize (or setsize) when the applet
is launched. All I get is a little frame window which I can then maximize
and see my applet. I think I have tried ever possible combination of the
Frame methods.

Could someone please lend a helping hand please don't make me beg.
Here is my watered down code.

import java.awt.*;

public class test extends java.applet.Applet {
Image currentimg;
Graphics currentGraphics;
Frame myframe;
static Dimension d;


public void init() {
myframe = new Frame("Test Applet");
d = Toolkit.getDefaultToolkit().getScreenSize();
myframe.add(this);
myframe.setSize(d.width, d.height);

...this becomes irrelevant
myframe.setVisible(true);
myframe.pack();

...here. Once you call 'pack', the method
asks the component what size it _wants_ to
be. Since all you have added at this point
is an applet (with nothing in it), it says it's
preferred size is zero..

OTOH, if you had added a Panel who's
preferredSize returned the size you want the
rendering to be, it would be that size.
myframe.show();
currentGraphics = getGraphics();
paint(currentGraphics);
}

HTH
 
A

Andrew Thompson

And I should add that you are trying to
add an applet whoich currently resides
in a browser, into the frame you just
created. You cannot do that.
(Or at least, not successfully)
..this becomes irrelevant


..here. Once you call 'pack', the method
asks the component what size it _wants_ to
be. Since all you have added at this point
is an applet (with nothing in it), it says it's
preferred size is zero..

OTOH, if you had added a Panel who's
preferredSize returned the size you want the
rendering to be, it would be that size.

...But then. You seem to have ignored me and
posted under a separate thread..
'Problem resizing applet frame', so I doubt that
you will either respond to, or learn anything from,
your messages here.
 
D

Danny Woods

Kevin said:
public void init() { :
myframe.setSize(d.width, d.height); :
myframe.pack();

The setSize is right. The pack is what's causing you problems. 'pack' causes
the frame to be sized according to the sizes of contained components. In this
case, your applet has no explicit size, and pack therefore believes that it
can squeeze the frame down to little more than a title bar. If you take out the
pack, you should be ok.

Regards,

Danny.
 
K

Kevin

I didn't think anyone saw my first thread when I posted it, so I posted it
one last time.

Anyways, I see what your saying about pack() not having any dimensional
object to pack and therefore not adjusting the frame accordingly. So I tried
it without pack() and the frame goes to the proper size, but doesn't display
my "hello world" string.
I tried using a panel but still couldn't see my "hello world"

All I'm trying to do is open a window that displays my applet and lets me
display images and draw a few things.
Is there a easier way?
 
K

Kevin

I tried it without pack() and the frame goes to the proper size, but doesn't
display my "hello world" string, until I hit the Maximize button on the
frame.

Any suggestions?
 
A

Andrew Thompson

.....
All I'm trying to do is open a window that displays my applet and lets me
display images and draw a few things.

OK. This is clearer. Let's take a few steps back. Why?

You say you want to display your applet
in a frame, but it seems you only need to
display a _string_ within the frame.

There are various ways to achieve that,
but first I would ask WHY you want to
pop-up a window (which will be branded
with words like 'Java Applet Window' or
such) outside a perfectly good browser
window. Applets are designed to do what
they do _inside_ a browser window..

Having something 'pop-up' is also considered
a web-design sin, as most users do not know
how to deal with pop-ups (and don't like them).
[ Of course.. - I have used them myself (pot,
kettle, black..!) ]

OK. Let us ignore the 'improperness' of
the pop-up and look at how to do it.

My experience with 'pop-ups' was when I
used an Applet that contained a button to
launch applications* (it is ridiculously simple)

* The applications were PToE, Calculet and
PocketPlanet, none of which attempted to
go outside the applet sandbox.

However, the Applet had little more to
do with the application once it was launched
(and certainly is not contained within it)

One thing you seem to be missing is that
your initial applet can only be located in _one_
place. It _starts_ in the browser window,
launches an external window, then tries to
put _itself_ in the new window.
(talk about pulling yourself up by the
bootstraps!)

Will not work. It might _conceivably_ work
if you created a second applet, or a second
instance of the first, but the one launching the
ext window is stuck in the browser that hosts it.

Of course, you could make the original applet
0x0 in size, launch the ext win, and do all your
components etc. in that - the user would be
unaware the applet ever existed (barring the
very obvious message at the bottom of the
ext window)

Another thing to note is that the ext window
is quite insubstantial, if the user surfs to another
page, it will vanish off screen..

So, I will not ramble on further, but instead
ask _why_ you want to do this the way you
describe, or better still, tell us what you want
the user to experience as they surf into the
page.

I should point out though, the chances of
you (or anyone else) using these techniques
to defraud or fool web-surfers, are slightly
less than that of a snow-ball in Hades.

If that is your intent, stop wasting your time.
 
A

Andrew Thompson

Andrew Thompson said:
.... .....
...it seems you only need to
display a _string_ within the frame.

Duh.. OK ...'display images and draw a few things'
 
K

Kevin

No malicious hacker here. I am creating...or I should say, have created an
interactive demonstration of our product. The product is some hardware that
plugs into a PDA and this demo allows a person to come onto our website and
play with this interactive demo to allow a person to experience the
functionality of our product. With touch screen PDA's that are in full color
it makes for cool interactivity and animation in this demo. There are no
traditional java buttons or layouts, I am simply tracking the users mouse
movements and mouse down events over the main image to animate my demo.

The reason I would like the applet to pop-up into its own window is because
the main image of PDA is almost 700 pixels high. Assuming a lot of people
will be running 1024x768 screen resolution, means that my applet gets
clipped off at the bottom because of all the web browser crap in the header
i.e.. address bar, tool bar ect.. So if I could just get it to pop up in
it's own window I would be a happy camper.

The code I posted is just an example that exhibits the same problems as my
interactive applet. The frame thing almost works in my applet but currently
the user would have to resize the frame himself, which is not really
desirable.

Should I be using HTML, or Jscript to do this. I am not very strong in these
languages.

Andrew Thompson said:
....
All I'm trying to do is open a window that displays my applet and lets me
display images and draw a few things.

OK. This is clearer. Let's take a few steps back. Why?

You say you want to display your applet
in a frame, but it seems you only need to
display a _string_ within the frame.

There are various ways to achieve that,
but first I would ask WHY you want to
pop-up a window (which will be branded
with words like 'Java Applet Window' or
such) outside a perfectly good browser
window. Applets are designed to do what
they do _inside_ a browser window..

Having something 'pop-up' is also considered
a web-design sin, as most users do not know
how to deal with pop-ups (and don't like them).
[ Of course.. - I have used them myself (pot,
kettle, black..!) ]

OK. Let us ignore the 'improperness' of
the pop-up and look at how to do it.

My experience with 'pop-ups' was when I
used an Applet that contained a button to
launch applications* (it is ridiculously simple)

* The applications were PToE, Calculet and
PocketPlanet, none of which attempted to
go outside the applet sandbox.

However, the Applet had little more to
do with the application once it was launched
(and certainly is not contained within it)

One thing you seem to be missing is that
your initial applet can only be located in _one_
place. It _starts_ in the browser window,
launches an external window, then tries to
put _itself_ in the new window.
(talk about pulling yourself up by the
bootstraps!)

Will not work. It might _conceivably_ work
if you created a second applet, or a second
instance of the first, but the one launching the
ext window is stuck in the browser that hosts it.

Of course, you could make the original applet
0x0 in size, launch the ext win, and do all your
components etc. in that - the user would be
unaware the applet ever existed (barring the
very obvious message at the bottom of the
ext window)

Another thing to note is that the ext window
is quite insubstantial, if the user surfs to another
page, it will vanish off screen..

So, I will not ramble on further, but instead
ask _why_ you want to do this the way you
describe, or better still, tell us what you want
the user to experience as they surf into the
page.

I should point out though, the chances of
you (or anyone else) using these techniques
to defraud or fool web-surfers, are slightly
less than that of a snow-ball in Hades.

If that is your intent, stop wasting your time.

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
 
A

Andrew Thompson

Kevin said:
No malicious hacker here. I am creating...or I should say, have created an
interactive demonstration of our product.

Let's take a shortcut here. What's your URL?
 
A

Andrew Thompson

Andrew Thompson said:
Let's take a shortcut here. What's your URL?

And the anwer to your question sounds more like
JavaScript (rather than JScript) by the moment,
though you would have to run it by the gurus of
JavaScript at c.l.javascript to ensure you come
up with a script that is cross-browser and degrades
gracefully.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top