Article View: pl.comp.lang.java
Article #154233Re: Jak nie reagować na kliknięcie buttona w Swingu?
From: Borneq
Date: Thu, 23 Jul 2015 13:30
Date: Thu, 23 Jul 2015 13:30
40 lines
2006 bytes
2006 bytes
W dniu 2015-07-23 o 15:12, Borneq pisze:
> kolejkowanie, nie wiem, jak bym tu zrobił runnable, to czy nie
> potworzyło by wielu wątków. Potrzebne jest coś w rodzaju globalnego
Tak, w wątkach, ale przy sprawdzaniu terminated:
field:
BenchWorker worker
class BenchWorker extends SwingWorker<Integer, Integer> {
String originalName;
protected boolean terminated;
BenchWorker(String name) {
originalName = name;
terminated = false;
}
@Override
protected Integer doInBackground() throws Exception {
if (originalName != null)
printBenchmarks(originalName);
terminated = true;
return null;
}
}
-------------------
buttonBench.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonBench.setEnabled(false);
if (worker == null || worker.terminated == true) {
worker = new BenchWorker(originalName);
worker.execute();
}
buttonBench.setEnabled(true);
}
});
Działa!
Technical Details
Message-ID:
<moqq9j$uhv$1@node1.news.atman.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mailReferences:
<moqiri$b1f$1@node2.news.atman.pl> <moql57$dfg$1@node2.news.atman.pl> <moqp72$hhq$1@node2.news.atman.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail From: Borneq <borneq@antyspam.hidden.pl> Newsgroups: pl.comp.lang.java Subject: Re: Jak nie reagować na kliknięcie buttona w Swingu? Date: Thu, 23 Jul 2015 15:30:27 +0200 Organization: ATMAN - ATM S.A. Lines: 40 Message-ID: <moqq9j$uhv$1@node1.news.atman.pl> References: <moqiri$b1f$1@node2.news.atman.pl> <moql57$dfg$1@node2.news.atman.pl> <moqp72$hhq$1@node2.news.atman.pl> NNTP-Posting-Host: 91.239.205.105 Mime-Version: 1.0 X-Trace: node1.news.atman.pl 1437658227 31295 91.239.205.105 (23 Jul 2015 13:30:27 GMT) X-Complaints-To: usenet@atman.pl NNTP-Posting-Date: Thu, 23 Jul 2015 13:30:27 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 In-Reply-To: <moqp72$hhq$1@node2.news.atman.pl> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit