Java Reference
In-Depth Information
How It Works
Drawing curves works in essentially the same way as drawing the other elements. The use of XOR mode
is superfluous with drawing a curve because you only extend it, but it would be quite a bit of work to treat
it as a special case. This would be justified only if drawing curves were too slow and produced excessive
flicker.
You might be wondering if you can change from XOR mode back to the normal mode of drawing in a
graphics context. Certainly you can: Just call the setPaintMode() method for the graphics context ob-
ject to get back to the normal drawing mode.
Figure 19-29 is mainly curves. In the next chapter you add a facility for adding text to a sketch. Don't
draw too many masterpieces yet. You won't be able to preserve them for the nation and posterity by sav-
ing them in a file until Chapter 21.
CHANGING THE CURSOR
As a last flourish in this chapter, you can make the cursor change to a crosshair cursor in the content pane
of the window. All that is necessary to do this is to implement the mouseEntered() and mouseExited()
methods in the MouseHandler inner class to the SketcherView class:
@Override
public void mouseEntered(MouseEvent e) {
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
Search WWH ::




Custom Search