0

我正在尝试制作一个显示可操作的 Jzy3D 图形的小程序。目前我已经设法让它显示图表,但无论如何我都无法影响它;这是有道理的,因为小程序目前不寻找任何用户输入。

我应该如何获取用户输入(鼠标移动、点击等)?我想我可以尝试创建一个信使类,它接收小程序输入并将其发送到 Jzy3D,然后 Jzy3D 进行移动并对其进行处理,但这似乎非常复杂。查看社区讨论板,建议使用 JOGLAppletLaucher。是为了绕过这个问题吗?如果是这样,它应该怎么做?

编辑:我相信我现在理解了 JOGLAppletLauncher(及其继任者 JNLPAppletLauncher)的意义,但如何传输用户输入的问题仍然存在。有任何想法吗?

我当前的代码:

package daniel.work;

import java.applet.Applet;

import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;

import com.sun.opengl.util.JOGLAppletLauncher;

public class SimpleApplet extends JApplet {

  public void start(){
      try{
          SwingUtilities.invokeAndWait(new Runnable(){
              public void run(){

                  add(ScatterCanvas.generateCanvas());

              }
          });
      }
      catch(Exception e){
          System.out.println(e);
      }
  }
}

package daniel.work;

import java.awt.Canvas;

import org.jzy3d.chart.Chart;
import org.jzy3d.colors.Color;
import org.jzy3d.demos.AbstractDemo;
import org.jzy3d.demos.Launcher;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.plot3d.primitives.Scatter;


public class ScatterCanvas extends AbstractDemo{

    public static Canvas generateCanvas(){
            // Create the dot cloud scene and fill with data
            int size = 2000;
            float x;
            float y;
            float z;
            float a;

            Coord3d[] points = new Coord3d[size];
            Color[]   colors = new Color[size];

            for(int i=0; i<size; i++){
                    x = (float)Math.random() - 0.5f;
                    y = (float)Math.random() - 0.5f;
                    z = (float)Math.random() - 0.5f;
                    points[i] = new Coord3d(x, y, z);
                    a = 0.25f + (float)(points[i].distance(Coord3d.ORIGIN)/Math.sqrt(1.3)) / 2;
                    colors[i] = new Color(x, y, z, a);
            }

            Scatter scatter = new Scatter(points, colors);
            chart = new Chart();
            chart.getScene().add(scatter);
            return (Canvas) chart.getCanvas();
    }


    protected static Chart chart;

    @Override
    public void init() throws Exception {
        // TODO Auto-generated method stub

    }

}

4

1 回答 1

0

知道了!这是我的代码。我还更改了我的 generateScatter 以现在返回图表“返回图表”,而不是 ICavnas

package myjogl;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.SwingUtilities;

import org.jzy3d.chart.Chart;
import org.jzy3d.chart.controllers.mouse.ChartMouseController;
import org.jzy3d.chart.controllers.thread.ChartThreadController;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;


@SuppressWarnings("serial")
public class JzyApplet extends JApplet implements ActionListener{

private Chart chart = null;
private ICanvas canvas = null;

public void init(){
    try{
        SwingUtilities.invokeAndWait(new Runnable(){
            public void run(){
                chart = ScatterCanvas.generateCanvas(); //this just returns a chart object with a scatter object
                canvas = chart.getCanvas();

                add((Component) canvas);                
            }
        });     
    }
    catch(Exception e){
        System.out.println(e);
    }   

    ChartMouseController mouse   = new ChartMouseController();

    chart.addController(mouse);


    ChartThreadController thread = new ChartThreadController();
    mouse.addSlaveThreadController(thread);
    chart.addController(thread);

    thread.start();

}

@Override
public void actionPerformed(ActionEvent e) {}

public void zoom(){
    float value = canvas.getView().getBounds().getXmax()-10;
    canvas.getView().getBounds().setXmax(value);
    canvas.getView().shoot();
}


}
于 2013-01-04T20:40:09.990 回答