Article View: borland.public.jbuilder.java.api
Article #2272Re: Waiting for a thread to finish
From: Valentino Kyriakides
Date: Tue, 17 Apr 2001 10:20
Date: Tue, 17 Apr 2001 10:20
83 lines
2732 bytes
2732 bytes
Torsten already gave you the correct answer. However, here are some rough
code fragments which show what Torsten means:
...
public class FTPApp extends JFrame
{
...
...
protected JButton startButton;
protected JButton stopButton;
...
protected FtpClient ftpClient; // <- class sun.net.ftp.FtpClient
...
public FTPApp() {
...
...
startButton = new JButton("Start");
lst = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (connect()) {
Thread downloader = new Thread() {
public void run() {
getFile(); // your getFile method or similar
disconnect();
}
};
downloader.start();
}
}
};
...
...
}
public void setButtonStates(boolean state) {
startButton.setEnabled(state);
stopButton.setEnabled(!state); // always inverse the state here
}
...
protected boolean connect() {
...
setButtonStates(false);
...
}
...
protected void disconnect() {
if (ftpClient != null) {
try { ftpClient.closeServer(); }
catch (IOException ex) {...}
ftpClient = null; // for garbage collection
}
Runnable runner = new Runnable() {
public void run() {
...
setButtonStates(true);
...
}
};
SwingUtilities.invokeLater(runner);
}
...
...
}
"Al Mal" <alex.im@nospam.usa.net> schrieb im Newsbeitrag
news:3adafaa4_1@dnews...
> In this case application will be frozen. I mean different: something like
> Delphi's OnTerminate event handler.
>
> Al
>
> "Torsten Welches" <torsten.welches@who.cares.netcologne.de> wrote in
message
> news:3adac7cd_1@dnews...
> > Al,
> >
> > look at the Thread.join() method.
> >
> > Torsten
>
>
>
Technical Details
Message-ID:
<3adc2068_1@dnews>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!feeds.vnews.net!ptdnetP!newsgate.ptd.net!news.maxwell.syr.edu!colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnewsReferences:
<3ada7468$1_1@dnews> <3adac7cd_1@dnews> <3adafaa4_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,609fa558749ab800 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2001-04-17 04:20:04 PST From: "Valentino Kyriakides" <vkyr@nospamlavielle.com> Newsgroups: borland.public.jbuilder.java.api References: <3ada7468$1_1@dnews> <3adac7cd_1@dnews> <3adafaa4_1@dnews> Subject: Re: Waiting for a thread to finish Date: Tue, 17 Apr 2001 12:20:19 +0200 Lines: 85 Organization: ISION X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 NNTP-Posting-Host: 194.64.62.36 Message-ID: <3adc2068_1@dnews> X-Trace: dnews 987504744 194.64.62.36 (17 Apr 2001 03:52:24 -0700) Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!feeds.vnews.net!ptdnetP!newsgate.ptd.net!news.maxwell.syr.edu!colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews