Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Dynamically resizing an applet

  1. #1
    Member
    Join Date
    Jun 2010
    Posts
    75
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Dynamically resizing an applet

    Is there away to dynamically resize an applet?

    I wrote some code to illustrate what I mean:

    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
     
    /*
    <applet code = SizeApplet.java width = 100 height = 100>
    </applet>
    */
     
    public class SizeApplet extends Applet
    {
         int curWidth = 0;
         int curHeight = 0;
         int newWidth = 0;
         int newHeight = 0;
     
         public void init()
         {
              curWidth = getWidth();
              curHeight = getHeight();
     
              MouseMotionAdapter resizer = new Resizer(this);
     
              this.addMouseMotionListener(resizer);
         }
    }
     
    class Resizer extends MouseMotionAdapter
    {
         SizeApplet sa;
     
         Resizer(SizeApplet sa)
         {
              this.sa = sa;
         }
     
         public void mouseDragged(MouseEvent me)
         {
              sa.newWidth = sa.getWidth();
              sa.newHeight = sa.getHeight();
     
              sa.showStatus("sa.newWidth = " + sa.newWidth + " sa.newHeight = " + sa.newHeight);
         }
    }

    What I want to do is to:

    1. implement some way of getting the dimensions of the applet widow after it has been manually resized calculate the ratio of the resized dimensions to the original dimensions
    2. multiply that coordinate of the graphical objects by the resizing ratios
    3. repaint the applet widow accordingly


    I am having trouble doing (1) and actually don't know if it possible. (2), (3), and (4) follow quite simply once (1) is achieved.

    Is there a event adapter class that I can use to get the dimensions of the resized applet window?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Dynamically resizing an applet

    It would seem you have to tell the browser to give you more space to enlarge where the applet shows. The applet tag has a width and height attributes that you are overriding.
    Maybe that problem doesn't exist now. ???

  3. #3
    Member
    Join Date
    Jun 2010
    Posts
    75
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Dynamically resizing an applet

    Quote Originally Posted by Norm View Post
    It would seem you have to tell the browser to give you more space to enlarge where the applet shows. The applet tag has a width and height attributes that you are overriding.
    Maybe that problem doesn't exist now. ???
    Are you saying that it can't be done all in Java? That you have to manipulate the HTML as well?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Dynamically resizing an applet

    I don't know what a browser would do. With the new javascript capabilities there is probably a way.
    Try writing a test program and see what happens from within the applet.

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Dynamically resizing an applet

    An applet cannot set/change it's size (for safety reasons). It must be changed in the webpage code (possibly via javascript).

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Dynamically resizing an applet

    Several years ago I tried to have an applet resize itself. Here's some very old code that does some of that. Use the links at the bottom to change to size of the applet. http://normsstuff.zxq.net/Testing/Applet_Resizer.html

  7. #7
    Member
    Join Date
    Jun 2010
    Posts
    75
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Dynamically resizing an applet

    Quote Originally Posted by Norm View Post
    Several years ago I tried to have an applet resize itself. Here's some very old code that does some of that. Use the links at the bottom to change to size of the applet. http://normsstuff.zxq.net/Testing/Applet_Resizer.html
    First, thank you for the example.

    I've read through the HTML source code several time and I'm wondering how of it is HTML.

    Is the only non-HTML code the last lines?

     <A HREF="javascript:document.myApplet.incrFont()">Increase Font</A>
    &nbsp;
    <A HREF="javascript:document.myApplet.decrFont()">Decrease Font</A>

Similar Threads

  1. Updating GUI dynamically
    By KrisTheSavage in forum AWT / Java Swing
    Replies: 2
    Last Post: August 29th, 2010, 08:23 AM
  2. dynamically resizing 2d array
    By Flamespewer in forum Collections and Generics
    Replies: 2
    Last Post: March 2nd, 2010, 11:10 AM
  3. [SOLVED] How to dynamically create ArrayLists (or something similar)?
    By igniteflow in forum Collections and Generics
    Replies: 4
    Last Post: August 6th, 2009, 06:00 AM
  4. Add Jmol applet dynimically in JSF(java server faces)
    By megha in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: May 15th, 2009, 06:16 AM
  5. JAVA Image Icon and JButton resizing problem
    By antitru5t in forum AWT / Java Swing
    Replies: 1
    Last Post: March 13th, 2009, 04:39 AM