Multiple Display Issues

Hi I am trying to integrate Jmonkey in my Swing Application.



Currently everything works great if I only create one panel with a Jmonkey window in it.



However I need to create 2 windows. Is this possible or not? If yes what do I need to change to achieve this. When i Instantiate the second panel containing Jmonkey neither appears and I get a bunch of null pointer exceptions.



Below is my code I use to make my panel. Works with only a single instance not multiples.



Thanks,

Simran B.



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Quaternion;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.Node;

import com.jme3.scene.debug.Arrow;

import com.jme3.scene.shape.Box;

import com.jme3.system.AppSettings;

import com.jme3.system.JmeCanvasContext;

import com.jme3.texture.Texture;



import java.awt.Color;

import java.awt.Dimension;

import java.awt.FlowLayout;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTextArea;





public class Shoe3DRotationPanel extends JPanel{

private int width = 300;//640;

private int height = 300;//480

private SmartShoeValues newestValue = null;

private SmartShoeValues lastValue = null;

//private float pitch = 0;

SwingCanvasTest canvasApplication;



public void update(SmartShoeValues in){

newestValue = in;

//canvasApplication.update();

}

public Shoe3DRotationPanel(){

super(new FlowLayout());

java.awt.EventQueue.invokeLater(new Runnable() {



public void run() {

// create new JME appsettings

AppSettings settings = new AppSettings(true);

settings.setWidth(width);

settings.setHeight(height);



// create new canvas application

canvasApplication = new SwingCanvasTest();

canvasApplication.setSettings(settings);

canvasApplication.createCanvas(); // create canvas!

JmeCanvasContext ctx = (JmeCanvasContext) canvasApplication.getContext();

ctx.setSystemListener(canvasApplication);

Dimension dim = new Dimension(width, height);

ctx.getCanvas().setPreferredSize(dim);





add(ctx.getCanvas()); // add JME canvas



canvasApplication.setPauseOnLostFocus(false);

canvasApplication.startCanvas();

}

});

}

public class SwingCanvasTest extends SimpleApplication {





protected Geometry platform, p_line;

Node pivot;

@Override

public void simpleInitApp() {

flyCam.setDragToRotate(true);

Box b = new Box(Vector3f.ZERO, (float)2, (float).05, (float)1);

platform = new Geometry(“red cube”, b);

Material mat = new Material(assetManager,

“Common/MatDefs/Misc/Unshaded.j3md”);

mat.setColor(“Color”, ColorRGBA.Red);

platform.setMaterial(mat);

//rootNode.attachChild(platform);



Box b2 = new Box(Vector3f.ZERO, (float)2.01, (float).1, (float).1);

p_line = new Geometry(“yellow cube”, b2);

Material mat2 = new Material(assetManager,

“Common/MatDefs/Misc/Unshaded.j3md”);

mat2.setColor(“Color”, ColorRGBA.Yellow);

p_line.setMaterial(mat2);

//rootNode.attachChild(p_line);



Arrow arrow = new Arrow(Vector3f.UNIT_X);

arrow.setLineWidth(5);

arrow.setArrowExtent(new Vector3f(2.3f, 0f, 0f));

Geometry geoArrow = new Geometry(“Arrow”, arrow);

Material mat3 = new Material(assetManager,

“Common/MatDefs/Misc/Unshaded.j3md”);

mat3.setColor(“Color”, ColorRGBA.Green);

geoArrow.setMaterial(mat3);





pivot = new Node(“pivot”);

rootNode.attachChild(pivot); // put this node in the scene



/** Attach the two boxes to the pivot node. /

pivot.attachChild(platform);

pivot.attachChild(p_line);



pivot.attachChild(geoArrow);

pivot.rotate(-0.2f, (float)Math.PI+.2f, 0f);

canvasApplication.setDisplayStatView(false);







}



/
This is the update loop */

@Override

public void simpleUpdate(float tpf) {

if(newestValue != null){

SmartShoeValues temp = newestValue;

float yawChange = temp.getRollRads();//temp.getYaw();

float rollChange = temp.getYawRads();//temp.getRoll();

float pitchChange = temp.getPitchRads();

if(lastValue != null){

yawChange -= lastValue.getRollRads();//lastValue.getYaw();

rollChange -= lastValue.getYawRads();//lastValue.getRoll();

pitchChange -= lastValue.getPitchRads();

}

lastValue = newestValue;

newestValue = null;



pivot.rotate(0, 0, pitchChange);

}





}



/public void simpleInitApp() {

// activate windowed input behaviour

flyCam.setDragToRotate(true);

// display a cube

Box boxshape1 = new Box(new Vector3f(-3f,1.1f,0f), 1f,1f,1f);

Geometry cube = new Geometry(“My Textured Box”, boxshape1);

Material mat_stl = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);

Texture tex_ml = assetManager.loadTexture(“Interface/Logo/Monkey.jpg”);

mat_stl.setTexture(“m_ColorMap”, tex_ml);

cube.setMaterial(mat_stl);

rootNode.attachChild(cube);

}
/



/public static void main(String[] args) {

java.awt.EventQueue.invokeLater(new Runnable() {



public void run() {

// create new JME appsettings

AppSettings settings = new AppSettings(true);

settings.setWidth(640);

settings.setHeight(480);



// create new canvas application

SwingCanvasTest canvasApplication = new SwingCanvasTest();

canvasApplication.setSettings(settings);

canvasApplication.createCanvas(); // create canvas!

JmeCanvasContext ctx = (JmeCanvasContext) canvasApplication.getContext();

ctx.setSystemListener(canvasApplication);

Dimension dim = new Dimension(640, 480);

ctx.getCanvas().setPreferredSize(dim);



// Create Swing window

JFrame window = new JFrame(“Swing Application”);

window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);



// Fill Swing window with canvas and swing components

JPanel panel = new JPanel(new FlowLayout()); // a panel

panel.add(ctx.getCanvas()); // add JME canvas

panel.add(new JButton(“Swing Component”)); // add some Swing

window.add(panel);

window.pack();



// Display Swing window including JME canvas!

window.setVisible(true);

canvasApplication.startCanvas();

}

});

}
/

}





}

To clairfy I dont mean windows as in different program instances. I mean panels that contain jmonkey elements

Look at TestAwtPanels. Same for your other post, use awt panels for multiple views.

When I try this test code the box only appears in one window.



Note I am trying to create 2 separate 3d images not 2 panels of the same 3d object.



Im really confused so I appreciate any help.