2012-10-17 6 views
0

다음과 같은 코드가있다 :jzy3d 3 번째 라이브러리에서 JFrame으로 채팅을 추가하는 방법은 무엇입니까?

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); 
    } 
} 

내가 차트 개체했습니다, 나는 내 JFrame의에 특별한 장소에 추가해야합니다. 그러나이 구조를 사용하려고하면 JComponent로 chart.getCanvas()를 형 변환하는 것에 대한 예외가 있습니다. 제발, 말해줘, 어떻게 고칠 수 있니? 미리 감사드립니다.

답변

2

CanvasJComponent이 아닙니다. awt는 Component입니다. 처음에는 캐스트를 만들 필요는 없지만 그렇게한다면 Component으로 캐스트하십시오.

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

자세한 내용

에 대한 the Javadocs를 참조하십시오
관련 문제