views:

131

answers:

2

We are designing physics app, and we would like to have it written in Java, and also we want to use root (root is writen in C++). Root has some nice graphical features -- it is able to draw very nice 3D charts, and I'm thinking whether it's possible to embedd those charts in Java app.

Is there any way to make C++ code draw on for example JPanel?

Is there a way to pass back mouse/keyboard events? - we would like to have some interactivity, like rotating a 3d chart.

I asked similar question about embedding a lot of C++ code (that is not related to drawing anything) in Java app (also about root) it's here.

+1  A: 

Since SWT is built to be a fairly thin wrapper around native widgets, it may be easier to work with than Swing/AWT for your particular task. I realize this particular link is a bit old, but it does show how to quickly wrap a native widget.

Suppressingfire
+1  A: 

The JNI comment on the question itself seems to be the best way forward - I don't think you want to draw with root as-is; you'll want to write some interface code in between which is called from Java via JNI, which asks 'root' to redraw its image at a given size (the appropriate size for the image being something only the java component would know). Pass it back to the java component from the JNI call as just 32-bit image data, for instance.

I would not assume you can draw into a java component even in AWT; as it's basically java wrappers around native components - where the drawing is usually done in the native component itself (by the operating system, not by the java code).

M1EK