Please...Applet frame resize problem

Discussion in 'Java' started by Kevin, Dec 11, 2003.

  1. Kevin

    Kevin Guest

    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);
    }
    }
    Kevin, Dec 11, 2003
    #1
    1. Advertising

  2. "Kevin" <> 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
    Andrew Thompson, Dec 11, 2003
    #2
    1. Advertising

  3. "Andrew Thompson" <> wrote in message
    news:b2UBb.48123$...
    > "Kevin" <> 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
    Andrew Thompson, Dec 11, 2003
    #3
  4. Kevin

    Danny Woods Guest

    "Kevin" <> 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.
    Danny Woods, Dec 11, 2003
    #4
  5. Kevin

    Kevin Guest

    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" <> wrote in message
    news:YJYBb.48477$...
    > "Andrew Thompson" <> wrote in message
    > news:b2UBb.48123$...
    > > "Kevin" <> 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
    >
    >
    Kevin, Dec 12, 2003
    #5
  6. Kevin

    Kevin Guest

    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" <> wrote in message
    news:...
    > "Kevin" <> 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.
    Kevin, Dec 12, 2003
    #6
  7. "Kevin" <> 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
    Andrew Thompson, Dec 12, 2003
    #7
  8. "Andrew Thompson" <> wrote in message
    news:lxbCb.49116$...
    > "Kevin" <> 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'
    Andrew Thompson, Dec 12, 2003
    #8
  9. Kevin

    Kevin Guest

    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" <> wrote in message
    news:lxbCb.49116$...
    > "Kevin" <> 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
    >
    >
    Kevin, Dec 12, 2003
    #9
  10. "Kevin" <> 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
    Andrew Thompson, Dec 12, 2003
    #10
  11. "Andrew Thompson" <> wrote in message
    news:NWcCb.49207$...
    > "Kevin" <> 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?


    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.

    --
    Andrew Thompson
    * http://www.PhySci.org/ PhySci software suite
    * http://www.1point1C.org/ 1.1C - Superluminal!
    * http://www.AThompson.info/andrew/ personal site
    Andrew Thompson, Dec 12, 2003
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KK
    Replies:
    2
    Views:
    528
    Big Brian
    Oct 14, 2003
  2. Replies:
    5
    Views:
    1,025
    Markus Weihs
    Apr 22, 2005
  3. wardemon

    Resize Frame

    wardemon, Nov 20, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    836
    wardemon
    Nov 21, 2006
  4. TPG
    Replies:
    10
    Views:
    6,185
    Mark Space
    Mar 6, 2008
  5. Replies:
    2
    Views:
    1,251
    Adrienne
    Feb 13, 2005
Loading...

Share This Page