Using Swing with jME

Can someone please explay the difference between the DisplaySystem.createCanvas() and  DisplaySystem.createWindow()? I assumed that the first creates am AWT Canvas that I can attach within a Swing application. But when I try to run this and then create a renderer it fails (class TestFails below).



However, if I add the createWindow() call the renderer call works, but still doesn't give me the canvas (TestWorks below). Clearly my assumption about the equivalence of these two calls (createCanvas and createWindow) is incorrect.



Perhaps putting the question another way will help it make sense. I want to get a Canvas I can render on that can be used in a Swing application. How can I modify the ClassWorks code to achieve this (and stop the separate window appearing in the middle of the screen)?



import com.jme.system.DisplaySystem;

import java.awt.Canvas;

import com.jme.renderer.Renderer;

import com.jme.renderer.lwjgl.LWJGLRenderer;



public class TestFails {

private int C_WIDTH = 200;

private int C_HEIGHT= 200;



public TestFails() {

DisplaySystem display = DisplaySystem.getDisplaySystem("LWJGL");

Canvas canvas = display.createCanvas(C_WIDTH, C_HEIGHT);

Renderer renderer = new LWJGLRenderer(C_WIDTH, C_HEIGHT);

}



public static void main(String[] args) { new TestFails(); }

}



This fails creating the renderer:



02-Feb-2006 12:30:01 com.jme.input.joystick.DummyJoystickInput <init>

INFO: Joystick support is disabled

02-Feb-2006 12:30:01 com.jme.system.lwjgl.LWJGLDisplaySystem <init>

INFO: LWJGL Display System created.

02-Feb-2006 12:30:01 com.jme.renderer.lwjgl.LWJGLRenderer <init>

INFO: LWJGLRenderer created. W:  200H: 200

java.lang.NullPointerException

at com.jme.scene.state.lwjgl.LWJGLTextureState.<init>(LWJGLTextureState.java:147)

at com.jme.renderer.lwjgl.LWJGLRenderer.createTextureState(LWJGLRenderer.java:314)

at com.jme.renderer.lwjgl.LWJGLRenderer.<init>(LWJGLRenderer.java:174)

at TestFails.<init>(TestFails.java:13)

at TestFails.main(TestFails.java:17)

Exception in thread "main"





This class works (ie doesn't crash!) but I must create a new Window in the middle of the screen (which I don't want).





import java.awt.Canvas;

import java.awt.FlowLayout;

import java.awt.Dimension;

import javax.swing.JPanel;



import com.jme.renderer.Renderer;

import com.jme.renderer.lwjgl.LWJGLRenderer;

import com.jme.system.DisplaySystem;



public class TestWorks extends javax.swing.JFrame {

private int C_WIDTH = 200;

private int C_HEIGHT= 200;



public TestWorks() {

DisplaySystem display = DisplaySystem.getDisplaySystem("LWJGL");

Canvas canvas = display.createCanvas(C_WIDTH, C_HEIGHT);

display.createWindow(C_WIDTH, C_HEIGHT, 32, 60, false);

Renderer renderer = new LWJGLRenderer(C_WIDTH, C_HEIGHT);



JPanel p = new JPanel();

p.add(canvas);

p.setLayout(new FlowLayout());

p.setPreferredSize(new Dimension(200, 200));

getContentPane().add§;

pack();

setVisible(true);

}



public static void main(String[] args) { new TestWorks(); }

}

You need to set an implementor. Again; you should really look at the JMESwingTest example.

Ah! I hadn't seen that class. Perfect.



Many thanks.