我正在尝试创建一个创建图形的applet,但applet会打开另一个窗口。
我不知道应该在代码中进行哪些更改才能使其正常工作。
我理解其原因是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() {
}
}
答案 0 :(得分:0)
开发人员指南提供了一个小程序示例(http://www.jzy3d.org/guide.php)。
请注意,applet不能在所有平台上轻松运行。我能够在Windows和Ubuntu上正常运行applet,但是在尝试在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应用程序。