//Point4.javaimport java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;public class Point4 extends Applet{
public BranchGroup createSceneGraph(){
//BranchGroup objects are the only objects that can be inserted into a Locale's set of objects. 
BranchGroup objRoot = new BranchGroup();
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Color3f bgColor = new Color3f(1.0f, 1.0f, 1.0f);
Background bg = new Background(bgColor);
bg.setApplicationBounds(bounds);
objRoot.addChild(bg); Shape3D shape = new Shape3D();
objRoot.addChild(shape);
objRoot.compile();
return objRoot;
} public Point4(){
setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
        Canvas3D c = new Canvas3D(config); add("Center", c);
BranchGroup scene = createSceneGraph();
SimpleUniverse u = new SimpleUniverse(c);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}

public static void main(String[] args){
new MainFrame(new Point4(), 400, 300);
}
}
//end of Point4.java
//pointShape.java
import javax.media.j3d.*;public class pointShape extends Shape3D{
float vert[] = {
0.5f, 0.5f, 0.0f,    -0.5f, 0.5f, 0.0f,
0.3f, 0.0f, 0.0f,    -0.3f, 0.0f, 0.0f,
-0.5f, -0.5f, 0.0f,  0.5f, -0.5f, 0.0f
};
float color[] = {
0.0f, 0.5f, 1.0f,  0.5f, 0.0f, 1.0f,
0.0f, 0.8f, 0.2f,  1.0f, 0.0f, 0.3f,
0.0f, 1.0f, 0.3f,  0.3f, 0.8f, 0.0f,
}; public pointShape(){
int[] index = {0, 2, 3, 4};
int vCount = 6;
int iCount = 4;
IndexedPointArray point = new IndexedPointArray(vCount,
IndexedPointArray.COORDINATES|IndexedPointArray.COLOR_3, iCount);
point.setCoordinates(0, vert);
point.setColors(0, color);
point.setCoordinateIndices(0, index);
point.setColorIndices(0, index); PointAttributes pa = new PointAttributes();
pa.setPointSize(20.0f);
pa.setPointAntialiasingEnable(true);//不加这一行,显示效果为正方形,加这一行,显示效果为圆形 Appearance ap = new Appearance();
ap.setPointAttributes(pa);
this.setGeometry(point);
this.setAppearance(ap);
}
}
//end of pointShape.java问题是怎样实现Point4.java调用pointShape.java这个程序的功能呢?初学java,很多东西都没接触过,还望各位多多指教!

解决方案 »

  1.   

    直接 PointShape ps = new PointShape();
      

  2.   

    对呀,java 3D的,不想把所有的内容都放在同一个.java文件里面,可是对于两个.java程序又不知如何调用运行~~
      

  3.   

    谢谢各位了,问题解决了,是我自己的程序写错了......
    Shape3D shape = new pointShape(); //
    然后直接编译运行就可以得到自己想要的图形了,结贴
      

  4.   

    public Point4(){
            setLayout(new BorderLayout());        GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
            Canvas3D c = new Canvas3D(config);        add("Center", c);
            BranchGroup scene = createSceneGraph();
            
            Transform3D m_t3d = new Transform3D(); //--------Here
            scene.addChild(m_t3d); //--------Here
            
          m_t3d.addChild(new PointShape());    //--------Here
         
            SimpleUniverse u = new SimpleUniverse(c);
            u.getViewingPlatform().setNominalViewingTransform();
            u.addBranchGraph(scene);
        }