A program doesn't stop a thread like it stops an
applet
(by calling a method). Rather, a thread arranges for
its own death by having a run method that terminates
naturally. For example, the while loop in this run
method is a finite loop-- it will iterate 100 times
and
then exit: 
public void run() {
    int i = 0;
    while (i < 100) {
        i++;
        System.out.println("i = " + i);
    }
}

A thread with this run method dies naturally when the
loop completes and the run method exits. 

One question I have - it looks like you are trying
to use Threads for Swing related code - is that 
true?  If you want Swing code to be run on a 
separate thread or have a task that takes a long
time ( or opens another Panel/Frame ) in Swing
Event handling code, take a look at using the
SwingWorker class.  If I'm misintrepreting your
code - "never mind".
-------------------------------
Considering the Certified Java Programmer Exam?
Get JCertify 5.0!
http://www.enterprisedeveloper.com/jcertify
2001 Java Developer Journal "Best Java Training
Program" recipient

--- "Conway. Fintan (IT Solutions)"
<[EMAIL PROTECTED]> wrote:
> Hi,
> 
>       Try scanThread.interrupt();.  This will stop the
> thread from
> running, but will not kill the thread.
> 
> > -----Original Message-----
> > From:       Panagiotis Plevrakis
> [SMTP:[EMAIL PROTECTED]]
> > Sent:       Friday, May 31, 2002 5:42 AM
> > To: JDJList
> > Subject:    [jdjlist] stopping a Thread
> > 
> > Can anybody show me a good non-deprecated way to
> stop scanThread in the 
> > following code? Setting it to null does not make
> her stop. What more
> > should 
> > I do to make her stop?
> >
>
************************************************************
> > btScan.addActionListener(new ActionListener() {
> >     public void actionPerformed(ActionEvent ae) {
> >         btScanCounter++;
> >         btScan.setText("Cancel Search");
> >         Thread t1 = new Thread() {
> >             public void run() {
> >                 handleScanButton();
> >             }};
> >         if ((btScanCounter%2) == 0) {
> >                 scanThread = null; // THIS DOES
> NOT WORK
> >             btScan.setText("Auto Search");
> >         } else {
> >             if (scanThread == null) {
> >                     scanThread = new Thread(t1);
> >                     scanThread.start();
> >             }
> >      }
> >       }});
> >
>
************************************************************
> > 
> >
>
_________________________________________________________________
> > Chat with friends online, try MSN Messenger:
> http://messenger.msn.com
> > 
> > 
> > To change your membership options, refer to:
> > http://www.sys-con.com/java/list.cfm
> 
> 
> * ** *** ** * ** *** ** * ** *** ** *
> This email and any files transmitted with it are
> confidential and
> intended solely for the use of the individual or
> entity to whom they
> are addressed. If you have received this email in
> error please notify
> the system manager.
> This message has been scanned for viruses.
> 
> * ** *** ** * ** *** ** * ** *** ** *
> 
> To change your membership options, refer to:
> http://www.sys-con.com/java/list.cfm


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to