problems of a simple rendering app please help

Hi

Two problems with a program as trivial as actively rendering a “hello” string on the canvas. First, BufferStrategy.contentsLost() always returns true



		try {
			//boolean contentsLost = bufferStrategy.contentsLost();
			boolean contentsLost = bufferStrategy.contentsLost()
					&& !bufferStrategy.contentsRestored();
			contentsLost = false;
			if (contentsLost && !renderer.onContentsLost()) {
				return;
			}

			while (!renderer.update())
				;

			if (contentsLost) {
				return;
			}

			Graphics g = bufferStrategy.getDrawGraphics();
			//Graphics g = getGraphics();
			if (null != g) {
				renderer.render(g);
				g.dispose();
			}
		} finally {
			bufferStrategy.show();
		}

Second, when the rendering canvas was added to the containing frame, layout management seems take no effect, and the canvas shrinks into itself at the top left corner of the frame. Did I missed anything?

Thanks in advance!

Would you kindly please view the whole source code at http://ultr_zero.googlegroups.com/web/ultr0-game-double-bufferred.jar?hl=en&gda=UJu7f1EAAABXNDLuhyWxmGuxQjc0_VHMPqokIIU9j8TUIm8x0xmn77pb5fMU98QuEZ7aBUAcFLaTR4qEDPm6rzSKuWq1gO8cUwk_6Qi3BU8HCN0q6OYwM5VxXgp_nHWJXhfr7YhqVgA&gsc=L7C0eRYAAAD4PX6IESzHsP7JEWesaD9ig-kXU5InE09W2o0GCSVgCQ?

The first problem may be caused by the second - make sure the canvass is visible and has a non-zero width and height. Add the canvas to a JFrame by calling frame.add(canvas) and the canvass should be added to fill up the jframe, since the BorderLayout is the default for JFrames and BorderLayout.CENTER is the default layout contraint for a BorderLayout.