【问题标题】:How to add Chat from jzy3d 3rd library to JFrame?如何将聊天从 jzy3d 3rd 库添加到 JFrame?
【发布时间】:2012-10-07 20:01:44
【问题描述】:

有如下代码:

public class SurfaceViewerFrame extends JFrame {

    public SurfaceViewerFrame() {
        setResizable(false);
        //System.loadLibrary("lib/jogl2-rc10/gluegen-rt.jar");
        Settings.getInstance().setHardwareAccelerated(true);
        FormLayout layout=new FormLayout("10px, 300px, 10px", "30px, 10px, 20px, 300px, 10px");
        CellConstraints сс=new CellConstraints();

        JLabel title=new JLabel("Выходная поверхность");


        Mapper mapper = new Mapper() {
            public double f(double x, double y) {
                return x * Math.sin(x * y);
            }
        };
        // Define range and precision for the function to plot
        Range range = new Range(-300, 300);
        int steps = 80;

        // Create the object to represent the function over the given range.
        final Shape surface = Builder.buildOrthonormal(new OrthonormalGrid(range, steps, range, steps), mapper);
        surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new Color(1, 1, 1, .5f)));
        surface.setFaceDisplayed(true);
        surface.setWireframeDisplayed(false);

        // Create a chart
        Chart chart = new Chart(Quality.Advanced, "awt");
        chart.getScene().getGraph().add(surface);
        chart.addController(new CameraKeyController());

        JPanel panel=new JPanel();
        panel.add(title, сс.xy(1, 1));
        panel.add((JComponent)chart.getCanvas(), CC.xy(1, 3));
        add(panel);
        setSize(320, 370);
        setVisible(true);
    }
}

我已经制作了 Chart 对象,然后我需要将它添加到我的 JFrame 中的特殊位置。但是当我尝试使用这种结构时,我得到了关于将 chart.getCanvas() 转换为 JComponent 的异常。请告诉我,我该如何解决?先感谢您。

【问题讨论】:

    标签: java swing canvas jframe awt


    【解决方案1】:

    Canvas 不是 JComponent - 它是 awt Component。您应该不需要首先进行演员表,但如果您这样做,请将其转换为 Component

    panel.add((Component)chart.getCanvas(), CC.xy(1, 3));
    

    更多信息请参见the Javadocs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-31
      • 1970-01-01
      • 2017-04-01
      • 2012-10-08
      • 2010-09-22
      • 2010-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多