Java Reference
In-Depth Information
theApp.getModel().add(tempElement); // ...add it to
the model...
tempElement = null; // ...and reset
the field
}
if(g2D != null) { // If there's a
graphics context
g2D.dispose(); // ...release the
resource...
g2D = null; // ...and reset
field to null
}
start = last = null; // Remove any
points
}
}
Directory "Sketcher 5 displaying a font dialog"
The method checks for a pop-up trigger event. If that's what the event is, the method displays the pop-up
menu either at
last
if it is not
null
, or at
start
. You could use the position that was stored in
start
by the
mousePressed()
method to display the pop-up, but if the pop-up is associated with the mouse
released event and the user drags the cursor before releasing the button, the menu appears at a different
position from where the button was released. This might look a little odd.
The
start
,
last
, and
buttonState
fields are reset before returning from the method. If it's not
the pop-up trigger event, the method executes exactly as before. No changes are necessary to the
mouseDragged()
method.
mouseClicked()
only responds to button 1 clicks when
TEXT
is the element
type, so that stays the same, too. If you recompile Sketcher and run it again, the pop-up menu should
appear in response to a right-button click, or whatever button triggers a context menu on your system.
The way it looks on my system is shown in
Figure 20-12
.