11package introprog
22
3- /** A window for pixel-based drawing in an underlying Swing window . */
3+ /** A module with utilities for event handling in `PixelWindow` instances . */
44object PixelWindow {
55 /** Immediately exit running application, close all windows, kills all threads. */
66 def exit (): Unit = System .exit(0 )
77
88 /** Idle waiting for `millis` milliseconds. */
99 def delay (millis : Long ): Unit = Thread .sleep(millis)
1010
11- /** An object with strings describing events that can happen in a PixelWindow, see [[ introprog.PixelWindow.Event ]] */
11+ /** An object with integers representing events that can happen in a PixelWindow. */
1212 object Event {
1313 /** An integer representing a key down event.
1414 *
@@ -57,7 +57,7 @@ object PixelWindow {
5757 */
5858 val Undefined = 0
5959
60- /** Returns a descriptive string with name of the `event` number */
60+ /** Returns a descriptive text for each `event`. */
6161 def show (event : Int ): String = event match {
6262 case KeyPressed => " KeyPressed"
6363 case KeyReleased => " KeyReleased"
@@ -71,14 +71,14 @@ object PixelWindow {
7171 }
7272}
7373
74- /** A window with a canvas for pixel-based drawing implemented using Swing .
74+ /** A window with a canvas for pixel-based drawing.
7575 *
7676 * @constructor Create a new window for pixel-based drawing.
77- * @param width the number of horizontal pixels of the drawing canvas inside the window
78- * @param height number of vertical pixels of the drawing canvas inside the window
77+ * @param width the number of horizontal pixels
78+ * @param height number of vertical pixels
7979 * @param title the title of the window
80- * @param background the background color filling the canvas when clearing pixels
81- * @param foreground the foreground color used as default argument for color parameters
80+ * @param background the color used when clearing pixels
81+ * @param foreground the foreground color, default color in drawing operations
8282 */
8383class PixelWindow (
8484 val width : Int = 800 ,
@@ -165,7 +165,7 @@ class PixelWindow(
165165 *
166166 * If time is out, `lastEventType` is `Undefined`.
167167 */
168- def awaitEvent (timeoutInMillis : Long ): Unit = {
168+ def awaitEvent (timeoutInMillis : Long = 1 ): Unit = {
169169 val e = eventQueue.poll(timeoutInMillis, java.util.concurrent.TimeUnit .MILLISECONDS )
170170 if (e != null ) handleEvent(e) else _lastEventType = Event .Undefined
171171 }
@@ -180,7 +180,7 @@ class PixelWindow(
180180 g.drawLine(x1, y1, x2, y2)
181181 }
182182
183- /** Fill a rectangle with upper left corner at `(x, y)` using `color` */
183+ /** Fill a rectangle with upper left corner at `(x, y)` using `color`. */
184184 def fill (x : Int , y : Int , width : Int , height : Int , color : java.awt.Color = foreground): Unit =
185185 canvas.withGraphics { g =>
186186 g.setColor(color)
@@ -205,10 +205,10 @@ class PixelWindow(
205205 }
206206
207207 /** Show the window. Has no effect if the window is already visible. */
208- def open (): Unit = Swing { frame.setVisible(true ) }
208+ def show (): Unit = Swing { frame.setVisible(true ) }
209209
210210 /** Hide the window. Has no effect if the window is already hidden. */
211- def close (): Unit = Swing { frame.setVisible(false ); frame.dispose() }
211+ def hide (): Unit = Swing { frame.setVisible(false ); frame.dispose() }
212212
213213 /** Clear all pixels using the `background` class parameter. */
214214 def clear (): Unit = canvas.withGraphics { g =>
0 commit comments