diff --git a/extras/edu/umd/cs/piccolox/PFrame.java b/extras/edu/umd/cs/piccolox/PFrame.java index 067b7b8..bca243f 100644 --- a/extras/edu/umd/cs/piccolox/PFrame.java +++ b/extras/edu/umd/cs/piccolox/PFrame.java @@ -98,7 +98,7 @@ // Make canvas bounds follow containing frame bounds addComponentListener(new ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent e) { - canvas.setBounds(0, 0, getWidth(), getHeight()); + canvas.setBounds(0, 0, getContentPane().getWidth(), getContentPane().getHeight()); } }); diff --git a/tests/PFrameTest.java b/tests/PFrameTest.java new file mode 100644 index 0000000..49570d0 --- /dev/null +++ b/tests/PFrameTest.java @@ -0,0 +1,27 @@ +import edu.umd.cs.piccolox.PFrame; +import junit.framework.TestCase; + +import java.awt.*; +import java.lang.reflect.InvocationTargetException; + +public class PFrameTest extends TestCase { + private static final int TEST_WIDTH = 500; + private static final int TEST_HEIGHT = 300; + + public PFrameTest(String name) { + super(name); + } + + public void testComponentResized() throws InvocationTargetException, InterruptedException { + final PFrame frame = new PFrame(); + frame.setBounds(0, 0, TEST_WIDTH, TEST_HEIGHT); + EventQueue.invokeAndWait(new Runnable() { + public void run() { + // clear the event queue + } + }); + Rectangle bounds = frame.getCanvas().getBounds(); + assertTrue("Canvas width should be inset by frame decoration size", bounds.getWidth() < TEST_WIDTH); + assertTrue("Canvas height should be inset by frame decoration size", bounds.getHeight() < TEST_HEIGHT); + } +} diff --git a/tests/RunAllUnitTests.java b/tests/RunAllUnitTests.java index 7878474..725cfc8 100644 --- a/tests/RunAllUnitTests.java +++ b/tests/RunAllUnitTests.java @@ -16,6 +16,7 @@ suite.addTest(new TestSuite(TransformActivityTest.class)); suite.addTest(new TestSuite(NotificationCenterTest.class)); suite.addTest(new TestSuite(PickTest.class)); + suite.addTest(new TestSuite(PFrameTest.class)); return suite; }