[vtkusers] Can't display a cone from vtk into a java window

Frederic kleinermann F.Kleinermann at pgr.salford.ac.uk
Tue Jan 23 05:22:47 EST 2001


Dear all,

I am trying to combine vtk with java using a very simple example having
a cone to be displayed. For that, I use vtkPanel. 

The simple program that I try to run, is the following 



import vtk.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
import sun.awt.*;
import java.beans.*;
import java.applet.Applet;
import java.awt.Graphics;
import javax.swing.JFrame;

public class MyCanvas extends Applet
{

        public static void main(String[] args)
        {

                MyCanvas myapp = new MyCanvas();
                
                vtkPanel pan = new vtkPanel();
                vtkConeSource cone = new vtkConeSource();
                vtkPolyDataMapper coneMapper = new vtkPolyDataMapper();
                coneMapper.SetInput(cone.GetOutput());
                vtkActor coneActor = new vtkActor();
                coneActor.SetMapper(coneMapper);
                pan.setActor(coneActor);
        
        }
}


But so far I can't manage to make it working. In fact, when I run that
program I have a window entitled Visualization Toolkit - WIN32OpengGl #1
which
appears with the cone in it and then disappears directly. When I make my
class
using that example deriving from either JFrame or Applet, the same
window
appears and this time stays, but there is no possible interaction  with
it or to
make things even worst, there is no repaint. This could come from the
fact that I
had to put in comments the following lines :

DrawingSurfaceInfo surfaceInfo =
     ((DrawingSurface)this.getPeer()).getDrawingSurfaceInfo();
   surfaceInfo.lock();

 MS windows support inthe next three lines      
     Win32DrawingSurface wds =
       (Win32DrawingSurface)surfaceInfo.getSurface();
     int hWnd = wds.getHWnd(); 

and I gave for hWnd, the default value 0. I had to do like that since
otherwise I had the following complaint :

Exception in thread "main" java.lang.NullPointerException
        at vtk.vtkPanel.getWindowID(vtkPanel.java:66)
        at vtk.vtkPanel.getWindowInfo(vtkPanel.java:91)
        at vtk.vtkPanel.Render(vtkPanel.java:124)
        at vtk.vtkPanel.setActor(vtkPanel.java:36)
        at MyCanvas.main(MyCanvas.java:36)

This is due to the fact that getPeer() is deprecated. 

Since I did install correctly vtk, I don't understand why I can't make a
simple example working. My aim is to get the rendering done in a java
window like it is possible with Microsoft visual c++. 


If anyone has experienced the same kind of problem, I would be very
grateful if you could help me.



Thanks




More information about the vtkusers mailing list