Dynamically resizing an applet
Is there away to dynamically resize an applet?
I wrote some code to illustrate what I mean:
Code Java:
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:
- 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
- multiply that coordinate of the graphical objects by the resizing ratios
- 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?
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. ???
Re: Dynamically resizing an applet
Quote:
Originally Posted by
Norm
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?
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.
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).
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
Re: Dynamically resizing an applet
Quote:
Originally Posted by
Norm
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?
Code Javascript:
<A HREF="javascript:document.myApplet.incrFont()">Increase Font</A>
<A HREF="javascript:document.myApplet.decrFont()">Decrease Font</A>