Java Reference
In-Depth Information
Display 19.1
Nonresponsive GUI
(part 3 of 3)
If you click the close-window button
while the circles are being drawn,
the window will not close until all
the circles are drawn.
The method
Thread.sleep
can throw an
InterruptedException
, which is a
checked exception—that is, it must be either caught in a
catch
block or declared in a
throws
clause. We do not discuss
InterruptedException
in this book , leaving it for
more advanced topics on multithreaded programming, but it has to do with one thread
interrupting another thread. We will simply note that an
InterruptedException
may be thrown by
Thread.sleep
and so must be accounted for—in our case, by a
simple
catch
block. The class
InterruptedException
is in the
java.lang
package
and so requires no import statement.