Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Please...Applet frame resize problem

Reply
Thread Tools

Please...Applet frame resize problem

 
 
Kevin
Guest
Posts: n/a
 
      12-11-2003
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);
}
}


 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      12-11-2003
"Kevin" <(E-Mail Removed)> wrote in message
news:H9TBb.54672$bC.13348@clgrps13...
> 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

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


 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      12-11-2003
"Andrew Thompson" <(E-Mail Removed)> wrote in message
news:b2UBb.48123$(E-Mail Removed)...
> "Kevin" <(E-Mail Removed)> wrote in message
> news:H9TBb.54672$bC.13348@clgrps13...
> > 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);


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)

> > 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);
> > }

>


...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.

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


 
Reply With Quote
 
Danny Woods
Guest
Posts: n/a
 
      12-11-2003
"Kevin" <(E-Mail Removed)> writes:

> 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.
 
Reply With Quote
 
Kevin
Guest
Posts: n/a
 
      12-12-2003
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?

"Andrew Thompson" <(E-Mail Removed)> wrote in message
news:YJYBb.48477$(E-Mail Removed)...
> "Andrew Thompson" <(E-Mail Removed)> wrote in message
> news:b2UBb.48123$(E-Mail Removed)...
> > "Kevin" <(E-Mail Removed)> wrote in message
> > news:H9TBb.54672$bC.13348@clgrps13...
> > > 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);

>
> 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)
>
> > > 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);
> > > }

> >

>
> ..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.
>
> --
> Andrew Thompson
> * http://www.PhySci.org/ PhySci software suite
> * http://www.1point1C.org/ 1.1C - Superluminal!
> * http://www.AThompson.info/andrew/ personal site
>
>



 
Reply With Quote
 
Kevin
Guest
Posts: n/a
 
      12-12-2003
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?

"Danny Woods" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Kevin" <(E-Mail Removed)> writes:
>
> > 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.



 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      12-12-2003
"Kevin" <(E-Mail Removed)> wrote in message
news:q2bCb.58323$bC.24601@clgrps13...
.....
> 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


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      12-12-2003
"Andrew Thompson" <(E-Mail Removed)> wrote in message
news:lxbCb.49116$(E-Mail Removed)...
> "Kevin" <(E-Mail Removed)> wrote in message
> news:q2bCb.58323$bC.24601@clgrps13...
> ....
> > All I'm trying to do is open a window that displays my applet and lets

me
> > display images and draw a few things.

.....
> ...it seems you only need to
> display a _string_ within the frame.


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


 
Reply With Quote
 
Kevin
Guest
Posts: n/a
 
      12-12-2003
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" <(E-Mail Removed)> wrote in message
news:lxbCb.49116$(E-Mail Removed)...
> "Kevin" <(E-Mail Removed)> wrote in message
> news:q2bCb.58323$bC.24601@clgrps13...
> ....
> > 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
>
>



 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      12-12-2003
"Kevin" <(E-Mail Removed)> wrote in message
news:9DcCb.58400$bC.27559@clgrps13...
> 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?

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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
resize external frame in "SingleFrameApplication"? TPG Java 10 03-06-2008 09:56 PM
How to get PAN newsreader to resize photos to fit in the body frame FJ Chaney Digital Photography 31 10-10-2007 12:56 AM
Resize Frame wardemon ASP .Net 2 11-21-2006 02:23 PM
How to prevent Tkinter frame resize? phil_nospam_schmidt@yahoo.com Python 5 04-22-2005 08:52 PM
How to resize all images sizes and coordinates of the images on resize browser rams.kakara@gmail.com ASP General 2 02-13-2005 09:03 AM



Advertisments