0% found this document useful (0 votes)
13 views2 pages

Lab07 Comments

The document provides solutions to common problems students encounter when creating a painting program in Java. It addresses issues such as mouse clicks not working consistently, content being erased when minimizing or overlapping the window, the color of lines not changing, sliders not appearing or functioning correctly, and errors related to implementing change listeners. Students are directed to Swing utilities, searching online documentation, or making specific code changes to resolve the issues.

Uploaded by

Peter Kong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Lab07 Comments

The document provides solutions to common problems students encounter when creating a painting program in Java. It addresses issues such as mouse clicks not working consistently, content being erased when minimizing or overlapping the window, the color of lines not changing, sliders not appearing or functioning correctly, and errors related to implementing change listeners. Students are directed to Swing utilities, searching online documentation, or making specific code changes to resolve the issues.

Uploaded by

Peter Kong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

[1] On some PCs the exact same code to detect right

mouse clicks will not work. I have not been able to


determine the root cause of this yet it is either a
hardware issue or a runtime problem (with multiple
java runtimes installed on the PC). I had only two cases
in lab ar2002 whilst the rest worked without problems.
To solve either make use of swing utilities
http://docs.oracle.com/javase/6/docs/api/javax/swing/S
wingUtilities.html#isLeftMouseButton(java.awt.event.M
ouseEvent) or create a button/label to click and handle
actionEvent to trigger the popup JColorChooser.
[2] Minimizing the application will cause all content on
screen to be erased. There is no way to avoid this
because we are not saving the JPanel contents when
the program is not active. Since this is out of the
syllabus scope we do not need to cover image buffering
but if students ask, you can direct them to search
Google for image buffering which will save the JPanel
content during Window minimize event and then
repaint() during reopening of the program window
[3] Had one PC in which calling the JColorChooser would
erase the entire JPanel whether or not it overlapped the
main program pane. Dont know if it was something
wrong with the students code (ran out of time to
debug) or not but everyone else didnt have this
problem so Im thinking it was student error. But note
that it is possible that if ANOTHER application overlaps
the Painter program it will erase the content because of
similar conditions with minimizing the window
[4] Resizing the window will cause paint() to redraw the
interface and guess what to fill in the back. To avoid
add the line this.Resizable(false); to the constructor
else tell student to google how to implement a
resizable JPanel with setBackground properties declared

in the method.
[5] Common mistakes if the color of the line does not
change student forgets to change the setColor
statement to the new variable, declared Color variable
is out of scope OR declared differently (spelling, case
etc)
[6] Slider cannot be seen remove paint()
[7] Can draw on top of slider yes because it is part of
the JFrame and we didnt set boundaries of where to
draw on. Cannot draw on label? because labels are
non-editable and cannot be changed > Java works in
mysterious ways
[8] Slider does not change size make sure the size
variable is used in the setStroke method.
[9] cannot find stateChanged method check to see if
ChangeListener is implements in the code
[10] Cannot find Changelistener check to see if
javax.swing.event.* is import in the code

You might also like