-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.0
-
x86
-
windows_nt
All platforms: Applet.preferredSize() returns a different value when the applet is run
in appletviewer then run as an application
Steps to reproduce
Compile and run the following code
Save HTML to ResizeTest.html
Run appletviewer ResizeTest.html
// compare the dimension values printed to stdout
// ----- ResizeTest.java -----
import java.applet.Applet;
import java.awt.*;
public class ResizeTest extends Applet
{
public void init()
{
String resizeType;
for (int i = 0; i < 10; i++)
{
add(new Button("Button"+i));
}
Dimension d = preferredSize();
System.out.println(d);
resize(d.width, d.height); // #1
}
public static void main(String a[])
{
AppletFrame.startApplet("ResizeTest", "Resize test");
}
}
/* Generic Applet to Application Frame
* @(#)AppletFrame.java 1.3 16 Nov 1995 17:26:57
* @author Kevin A. Smith
* The class AppletFrame provides a simple AWT Frame window for running
* applications.
*
*/
import java.awt.Frame;
import java.awt.Event;
import java.awt.Dimension;
import java.applet.Applet;
// Applet to Application Frame window
class AppletFrame extends Frame
{
public static void startApplet(String className, String title)
{
// local variables
Applet a;
Dimension appletSize;
try
{
// create an instance of your applet class
a = (Applet) Class.forName(className).newInstance();
}
catch (ClassNotFoundException e) { return; }
catch (InstantiationException e) { return; }
catch (IllegalAccessException e) { return; }
// initialize the applet
a.init();
a.start();
// create new application frame window
AppletFrame f = new AppletFrame(title);
// add applet to frame window
f.add("Center", a);
// resize frame window to fit applet
// assumes that the applet sets its own size
// otherwise, you should set a specific size here.
appletSize = a.size();
f.pack();
f.resize(appletSize);
// show the window
f.show();
} // end startApplet()
// constructor needed to pass window title to class Frame
public AppletFrame(String name)
{
// call java.awt.Frame(String) constructor
super(name);
}
// needed to allow window close
public boolean handleEvent(Event e)
{
// Window Destroy event
if (e.id == Event.WINDOW_DESTROY)
{
// exit the program
System.exit(0);
return true;
}
// it's good form to let the super class look at any
// unhandled events
return super.handleEvent(e);
} // end handleEvent()
} // end class AppletFrame
// ----- ResizeTest.html -----
<HTML>
<HEAD>
<TITLE> resize bug </TITLE>
</HEAD>
<BODY>
<BR>
<APPLET CODE="ResizeTest.class" WIDTH=150 HEIGHT=25>
<Param name = "resize" value = "int">
</APPLET>
</BODY>
</HTML>
in appletviewer then run as an application
Steps to reproduce
Compile and run the following code
Save HTML to ResizeTest.html
Run appletviewer ResizeTest.html
// compare the dimension values printed to stdout
// ----- ResizeTest.java -----
import java.applet.Applet;
import java.awt.*;
public class ResizeTest extends Applet
{
public void init()
{
String resizeType;
for (int i = 0; i < 10; i++)
{
add(new Button("Button"+i));
}
Dimension d = preferredSize();
System.out.println(d);
resize(d.width, d.height); // #1
}
public static void main(String a[])
{
AppletFrame.startApplet("ResizeTest", "Resize test");
}
}
/* Generic Applet to Application Frame
* @(#)AppletFrame.java 1.3 16 Nov 1995 17:26:57
* @author Kevin A. Smith
* The class AppletFrame provides a simple AWT Frame window for running
* applications.
*
*/
import java.awt.Frame;
import java.awt.Event;
import java.awt.Dimension;
import java.applet.Applet;
// Applet to Application Frame window
class AppletFrame extends Frame
{
public static void startApplet(String className, String title)
{
// local variables
Applet a;
Dimension appletSize;
try
{
// create an instance of your applet class
a = (Applet) Class.forName(className).newInstance();
}
catch (ClassNotFoundException e) { return; }
catch (InstantiationException e) { return; }
catch (IllegalAccessException e) { return; }
// initialize the applet
a.init();
a.start();
// create new application frame window
AppletFrame f = new AppletFrame(title);
// add applet to frame window
f.add("Center", a);
// resize frame window to fit applet
// assumes that the applet sets its own size
// otherwise, you should set a specific size here.
appletSize = a.size();
f.pack();
f.resize(appletSize);
// show the window
f.show();
} // end startApplet()
// constructor needed to pass window title to class Frame
public AppletFrame(String name)
{
// call java.awt.Frame(String) constructor
super(name);
}
// needed to allow window close
public boolean handleEvent(Event e)
{
// Window Destroy event
if (e.id == Event.WINDOW_DESTROY)
{
// exit the program
System.exit(0);
return true;
}
// it's good form to let the super class look at any
// unhandled events
return super.handleEvent(e);
} // end handleEvent()
} // end class AppletFrame
// ----- ResizeTest.html -----
<HTML>
<HEAD>
<TITLE> resize bug </TITLE>
</HEAD>
<BODY>
<BR>
<APPLET CODE="ResizeTest.class" WIDTH=150 HEIGHT=25>
<Param name = "resize" value = "int">
</APPLET>
</BODY>
</HTML>