I have a question of stopping a thread. I studied the API that I know
that the interrupt will stop a thread. But here is my code:
public void mouseMoved(MouseEvent e){
if(e.getX() <= 1 || e.getX() >= boundary.width - 1 ||
e.getY() <= 1 || e.getY() >= boundary.height - 1){
// Update the mouse position in the camera
before starting or checking the thread
camera.setMousePosition(e.getX(), e.getY());
if(cam.isInterrupted()){
camera.setChecking(true);
cam.start();
System.out.println("Camera is start()" +
e.getX() + ":" + e.getY());
}
}else{
camera.setMousePosition(e.getX(), e.getY());
if(!cam.isInterrupted()){
camera.setChecking(false);
try{
cam.interrupt();
}catch(Exception exception){}
System.out.println("Camera is
interrupt()" + e.getX() + ":" + e.getY());
}
}
}
As you can see that if the isInterrupted() returns false in the else
statement, then it will interrupt the thread, which implies that the
thread is alive and still running so it will interrupt the thread,
right? but everytime I have mouseMoved() detected, it checks if the
mouse pointer is in the area or not, if it is, checks if it is
interrupted or not, if it is interrupted or not, if it is interrupted,
which means it should start the thread again; if it is not interrupted,
which means it's running, it will interrupt. But whenever I move my
mouse in the area, it starts the thread, then once I interrupt the
thread, no matter where I move(exception the area I wanna do something
with, which will start the thread), it just goes into the if statement
showing "Camera is interrupted()"
Any hints?
Many thanks,
Andy
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".