经过几天的努力,终于让 本来应该在Frame中的WireSurface chart 嵌入 到了 Applet中。效果图如下:
代码如下:
jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="pragma" content="no-cache"/> <meta http-equiv="cache-control" content="no-cache"/> <meta http-equiv="expires" content="0"/> <title>Insert title here</title> </head> <body> <applet code="HelloApplet" width=800 height=600 codebase="./" archive="org.jzy3d-0.9.jar, gluegen-rt.jar, gluegen-rt-natives-windows-i586.jar, jogl-all.jar, jogl-all-natives-windows-i586.jar" ></applet> </body> </html>
Applet:
import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JApplet; import org.jzy3d.chart.Chart; import org.jzy3d.chart.ChartLauncher; import org.jzy3d.demos.IDemo; import org.jzy3d.demos.surface.WireSurfaceDemo; import org.jzy3d.global.Settings; import org.jzy3d.plot3d.rendering.canvas.ICanvas; public class HelloApplet extends JApplet implements ActionListener{ private Chart chart; private ICanvas canvas; public void paint(Graphics g) { super.paint(g); } @Override public void init() { try { IDemo demo = new WireSurfaceDemo(); Settings.getInstance().setHardwareAccelerated(true); demo.init(); this.chart = demo.getChart(); boolean allowSlaveThreadOnDoubleClick = true; boolean startThreadImmediatly = true; ChartLauncher.configureControllers(chart, "title",allowSlaveThreadOnDoubleClick, startThreadImmediatly); chart.render(); this.canvas = chart.getCanvas(); getContentPane().add((java.awt.Component)this.canvas); } catch (Exception e) { e.printStackTrace(); }finally{ } } @Override public void actionPerformed(ActionEvent e) { } }
WireSurfaceDemo:
package org.jzy3d.demos.surface; import org.jzy3d.chart.Chart; import org.jzy3d.colors.Color; import org.jzy3d.colors.ColorMapper; import org.jzy3d.colors.colormaps.ColorMapRainbow; import org.jzy3d.demos.AbstractDemo; import org.jzy3d.demos.DemoLauncher; import org.jzy3d.maths.Range; import org.jzy3d.plot3d.builder.Builder; import org.jzy3d.plot3d.builder.Mapper; import org.jzy3d.plot3d.builder.concrete.Chart4Grid; import org.jzy3d.plot3d.builder.concrete.OrthonormalGrid; import org.jzy3d.plot3d.primitives.Shape; import org.jzy3d.plot3d.rendering.canvas.Quality; public class WireSurfaceDemo extends AbstractDemo { public static void main(String[] args) throws Exception { DemoLauncher.openDemo(new WireSurfaceDemo()); } public WireSurfaceDemo() { } @Override public void init() { // Define a function to plot Mapper mapper = new Mapper() { public double f(double x, double y) { return 10 * Math.sin(x / 10) * Math.cos(y / 20) * x; } }; // Define range and precision for the function to plot Range range = new Range(-150, 150); int steps = 50; // OrthonormalGrid grid = new OrthonormalGrid(range, steps, range, steps); OrthonormalGrid grid = new Chart4Grid(range, steps, range, steps, data); // Create the object to represent the function over the given range. final Shape surface = Builder.buildOrthonormal(grid, mapper); surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new Color(1, 1, 1, .5f))); surface.setFaceDisplayed(true); surface.setWireframeDisplayed(true); surface.setWireframeColor(Color.BLACK); // Create a chart and add surface chart = new Chart(Quality.Advanced, getCanvasType()); chart.getScene().getGraph().add(surface); } @Override public String getPitch() { return "Show a simple surface based on a mathematical function"; } public double data[][] = {{-150.0,-150.0,338.1191},
相关的jar文件:
gluegen.jar
gluegen-rt.jar
jogl-all.jar
gluegen-rt-natives-windows-i586.jar
jogl-all-natives-windows-i586.jar
org.jzy3d-0.9.jar