Path: csiph.com!aioe.org!aspen.stu.neva.ru!goblin2!goblin.stu.neva.ru!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail From: Borneq Newsgroups: pl.comp.lang.java Subject: =?UTF-8?Q?Re:_Jak_nie_reagowa=c4=87_na_klikni=c4=99cie_buttona_w_Sw?= =?UTF-8?Q?ingu=3f?= Date: Thu, 23 Jul 2015 15:30:27 +0200 Organization: ATMAN - ATM S.A. Lines: 40 Message-ID: References: NNTP-Posting-Host: 91.239.205.105 Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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: Xref: aioe.org pl.comp.lang.java:10766 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 { 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!