0

我正在尝试创建一个可创建图形的小程序,但该小程序会打开另一个窗口。我不知道应该对代码进行哪些更改才能使其正常工作。我知道它的原因是ChartLauncher

import java.applet.Applet;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.List;

import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;

import org.jzy3d.chart.Chart;
import org.jzy3d.chart.ChartLauncher;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.plot3d.primitives.Point;
import org.jzy3d.plot3d.primitives.Polygon;
import org.jzy3d.plot3d.primitives.Shape;

import com.jogamp.opengl.util.FPSAnimator;


public class AppletPolygons  extends Applet{
private GLAnimatorControl glanimatorcontrol;

public void init() {
    GLProfile.initSingleton();
    setLayout( new BorderLayout() );        

    final GLCanvas glcanvas = new GLCanvas();
    glcanvas.addGLEventListener( new GLEventListener() {

        @Override
        public void reshape(GLAutoDrawable arg0, int arg1, int arg2,
                int arg3, int arg4) {

        }

        @Override
        public void init( GLAutoDrawable glautodrawable ) {
            // Build a polygon list
            double [][]distDataProp = new double[][] {{5,10, .20},{10, 20, .45}, {30, 40,.7}};
            List<Polygon> polygons = new ArrayList<Polygon>();
            for(int i = 0; i < distDataProp.length -1; i++){
                for(int j = 0; j < distDataProp[i].length -1; j++){
                    Polygon polygon = new Polygon();
                    polygon.add(new Point( new Coord3d(i, j, distDataProp[i][j]) ));
                    polygon.add(new Point( new Coord3d(i, j+1, distDataProp[i][j+1]) ));
                    polygon.add(new Point( new Coord3d(i+1, j+1, distDataProp[i+1][j+1]) ));
                    polygon.add(new Point( new Coord3d(i+1, j, distDataProp[i+1][j]) ));

                    if ((j % 2) == 0)
                        polygon.setColor(Color.RED);
                    else
                        polygon.setColor(Color.GREEN);
                    polygons.add(polygon);
                }
            }

            Point p = new Point();
            Coord3d n = new Coord3d();
            n.x=100;
            n.y=5;
            n.z=2;
            p.setData(n);
            p.setWidth(10);
            p.setColor(Color.BLACK);

            Polygon polygon = new Polygon();
            polygon.add(new Point( new Coord3d(1, 2, -1*distDataProp[0][0]) ));
            polygon.add(new Point( new Coord3d(1, 3, -1*distDataProp[0][1]) ));
            polygon.add(new Point( new Coord3d(2, 3, -1*distDataProp[1][1]) ));
            polygon.add(new Point( new Coord3d(2, 2, -1*distDataProp[1][0]) ));

            polygon.setColor(Color.MAGENTA);

            polygons.add(polygon);

            // Creates the 3d object
            Shape surface = new Shape(polygons);
            surface.add(p);
            surface.setWireframeDisplayed(true);
            surface.setWireframeColor(org.jzy3d.colors.Color.BLACK);

            Chart chart = new Chart();

            chart.getScene().getGraph().add(surface);

            chart.getAxeLayout().setXTickColor(Color.CYAN);
            chart.getAxeLayout().setYTickColor(Color.BLUE);
            chart.getAxeLayout().setZTickColor(Color.BLUE);

            ChartLauncher.openChart(chart, "my garph");         

        }

        @Override
        public void dispose( GLAutoDrawable glautodrawable ) {
        }

        @Override
        public void display( GLAutoDrawable glautodrawable ) {

            }

    });

    glcanvas.setSize( getSize() );
    add( glcanvas, BorderLayout.CENTER );
    glanimatorcontrol = new FPSAnimator( glcanvas, 30 );
}

public void start() {
    glanimatorcontrol.start();
}

public void stop() {
    glanimatorcontrol.stop();
}

public void destroy() {
}
}
4

1 回答 1

0

开发人员指南提供了一个小程序示例 ( http://www.jzy3d.org/guide.php )。

请注意,小程序并不容易在所有平台上运行。我能够让一个小程序在 Windows 和 Ubuntu 上正常运行,但是当我试图在 MacOS+Chrome 上运行它时卡住了。

您可能希望在购买指南之前尝试运行示例:http ://www.jzy3d.org/release/0.9/applet/jzy3d-applet.html

如果您想使用 JNLP,那么您应该查看此页面 ( http://jogamp.org/wiki/index.php/Using_JOGL_in_Java_Web_Start ),说明如何打包基于 JOGL 的 JNLP 应用程序。

于 2014-09-04T12:03:25.317 回答