In the following code, I create an awt Frame. Unfortunately, when I
run the resulting Java application (on Windows) and use the mouse to
resize the window, none of the Frame's resize/setSize methods get
called. Can anyone explain why this is?
Thanks
Greg
import java.awt.* ;
public class Junk extends Frame
{
public static void main (String args[])
{
Junk j = new Junk ();
j.show ();
}
public void resize(Dimension arg0)
{
super.resize(arg0);
}
public void resize(int arg0, int arg1)
{
super.resize(arg0, arg1);
}
public void setSize(Dimension arg0)
{
super.setSize(arg0);
}
public void setSize(int arg0, int arg1)
{
super.setSize(arg0, arg1);
}
}
A. Bolmarcich - 21 Nov 2003 17:25 GMT
> In the following code, I create an awt Frame. Unfortunately, when I
> run the resulting Java application (on Windows) and use the mouse to
> resize the window, none of the Frame's resize/setSize methods get
> called. Can anyone explain why this is?
It happens because using the mouse to resize the window invokes a method
of a java.awt.peer.Frame object rather than a java.awt.Frame. A
java.awt.Frame class handles the implementation independent behavior of
a frame, while the corresponding peer class handles the implementation
dependent behavior. Conceptually, the same java.awt.Frame class can be
used by all implementations of Java. Each implementation will have to
provide the correspoinding peer class.
If you want to be informed that the size of a frame has changed, add
a ComponentListener to the frame. The componentResized(ComponentEvent)
method of the ComponentListener will be invoked after the size has
changed.