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:
- 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?