Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.java.programmer Subject: Re: What do you think of my CropImage class Date: Thu, 21 Jul 2016 18:12:10 +0200 Organization: Decebal Computing Lines: 46 Message-ID: <87h9bj55t1.fsf@Equus.decebal.nl> References: <87twfk93vu.fsf@Equus.decebal.nl> <87vazz71ct.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="12baf5125b19322b899c79c2e3878015"; logging-data="14123"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+oR4XQ4ABS1C11Nia99QoyUUgPN+uBAZE=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:KRwu6jK4t0BXadxIPahTnYVJuhk= sha1:iHtW7D01qJVcW5uZCn/OPlrHqPk= Xref: csiph.com comp.lang.java.programmer:35054 On Thursday 21 Jul 2016 17:13 CEST, Eric Sosman wrote: > On 7/21/2016 10:58 AM, Knute Johnson wrote: >> On 7/21/2016 03:05, Cecil Westerhof wrote: >>> >>>> Runnable r = new Runnable() { >>>> public void run() { >>>> try { >>>> ImageIO.write(subImage,"JPEG",new >>>> File("crop.jpg")); >>>> } catch (IOException ioe) { >>>> ioe.printStackTrace(); >>>> } >>>> } >>>> }; >>>> new Thread(r).start(); >>> >>> Why are you doing this in a separate thread? >>> >> >> So if you have a large image that takes a second or two to write it >> won't block the Event Dispatch Thread and mess up the mouse >> movement. > > A slightly slicker way to do this is with a SwingWorker, the > advantage being that it can inform the GUI when the save completes. > You could then display a JDialog if there was a problem, or arrange > to display a busy cursor while the save runs and restore the > original cursor afterward, or ... > > SwingWorker is, however, a bit more complex than a "fire and forget" > Thread, so CW might choose to stick with the simpler alternative for > now and revisit the fancier one later on. > > http://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html I keep getting homework. :-D Probably nice to do, but there are a lot of things I have to do that are a lot more important. So I am probably going to do it, but it could take a while. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof