When I try to add a KeyListener object for some swing component outside of this component constructor KeyListener doesn’t answer after, why? For example:
public class ActionViewer extends SimpleViewer
implements ActionListener
{
public ActionViewer(Dimension __wndSize, String pgnPath,
PerspectiveProjection __persp)
{
super(__wndSize, pgnPath, __persp);
...
cMng=null;
...
}
///
public void setCamera(double xMin, double xMax,
double yMin, double yMax,
double zMin, double zMax)
{
if(!isCameraInit())
{
if(cMng==null)
cMng=new CameraControl();
this.addKeyListener((KeyListener)cMng);
fCamInit=true;
}
setCameraBounds(xMin, xMax, yMin, yMax, zMin, zMax);
}
...
}
When I call setCamera in main there is nothing happen.
...
ActionViewer scene = new ActionViewer(wndSize, pgnPath, persp);
scene.setCamera(xMin, xMax, yMin, yMax, zMin, zMax);
...
I think there is some problem of initialization, Could you check place of init listener just
try{}catchall methodsetCameraand print all problems, it should help you to find problem.