Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

drawing java3d on JPanel

843799Nov 12 2006 — edited Jan 4 2007
hi,

i want to draw my java3D object or wireframes on JPanel, so that i can use netbeans to position a JPanel any were in the frame i want then just assin that to my Java3D JPanel..

can some one help provide me with simple code that will create a 3D univers like the canvas 3D but on JPanel??

my aim is port this code to show on JPanel , no applet .. just JPanel.


import java.awt.Frame;

import java.applet.Applet;

import java.awt.*;

import java.awt.event.*;

import com.sun.j3d.utils.applet.MainFrame;

import com.sun.j3d.utils.geometry.*;

import com.sun.j3d.utils.universe.*;

import javax.media.j3d.*;

import javax.vecmath.*;



public class lesson03 extends Applet {

SimpleUniverse simpleU;

public Appearance getWireframeAppearance() {
Appearance app = new Appearance();
Color awtColor = new Color(255, 255, 0);// use any Color you like
Color3f color = new Color3f(awtColor);
ColoringAttributes ca = new ColoringAttributes();
ca.setColor(color);
app.setColoringAttributes(ca);
PolygonAttributes pa = new PolygonAttributes();
pa.setPolygonMode(pa.POLYGON_LINE);
pa.setCullFace(pa.CULL_NONE);
app.setPolygonAttributes(pa);
return app;
}

public BranchGroup createSceneGraph() {

BranchGroup objRoot = new BranchGroup();

Appearance polygon1Appearance = getWireframeAppearance();
QuadArray polygon1 = new QuadArray (4, QuadArray.COORDINATES);
polygon1.setCoordinate (0, new Point3f (0f, 0f, 0f));
polygon1.setCoordinate (1, new Point3f (2f, 2f, -1f));
//polygon1.setCoordinate (2, new Point3f (2f, 3f, 0f));
//polygon1.setCoordinate (3, new Point3f (0f, 3f, 0f));
objRoot.addChild(new Shape3D(polygon1,polygon1Appearance));
return objRoot;


}



public lesson03 (){

}



public void init() {



setLayout(new BorderLayout());

Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration());

add("Center", c);



BranchGroup scene = createSceneGraph();

simpleU = new SimpleUniverse(c);

TransformGroup tg = simpleU.getViewingPlatform().getViewPlatformTransform();

Transform3D t3d = new Transform3D();
t3d.setTranslation(new Vector3f(0f,0f,10f));
tg.setTransform(t3d);

scene.compile();

simpleU.addBranchGraph(scene);

}


public void destroy(){
simpleU.removeAllLocales();
}


public static void main(String[] args) {

Frame frame = new MainFrame(new lesson03(), 500, 500);

}

}


im still expermineting and learning java3D and i want to use this code and minimize it "strip it of all applet stuff" and just have it show on JPanel so that i can place it in swing JFrame and some controls "buttons and textfields" in netbeans to experiment with coordinate drawing and so on..

peace
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 1 2007
Added on Nov 12 2006
2 comments
1,242 views