|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.event.MouseInputAdapter
Graphics2DTestPlusButton.MovableButtonMouseListener
Class MovableButtonMouseListener extends JFC's MouseInputAdpater to provide handlers for three mouse events: mouse pressed, mouse dragged, and mouse released. The comments for the event-handling methods describe in detail what each method does to allow the button to be movable on the drawing canvas.
Field Summary | |
protected int |
normalizeX
The normalized x coordinate of where the mouse is pressed on the button |
protected int |
normalizeY
The normalized y coordinate of where the mouse is pressed on the button |
Constructor Summary | |
Graphics2DTestPlusButton.MovableButtonMouseListener()
|
Method Summary | |
void |
mouseDragged(java.awt.event.MouseEvent e)
Drag the movingButton around. |
void |
mousePressed(java.awt.event.MouseEvent e)
Respond to the initial mouse press by allocating a visual clone of the button and hiding the button temporarily. |
void |
mouseReleased(java.awt.event.MouseEvent e)
Move the original button to the ending position of the movingButton, make the button visible again, and get rid of the movingButton. |
Methods inherited from class javax.swing.event.MouseInputAdapter |
mouseClicked, mouseEntered, mouseExited, mouseMoved |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int normalizeX
protected int normalizeY
Constructor Detail |
public Graphics2DTestPlusButton.MovableButtonMouseListener()
Method Detail |
public void mousePressed(java.awt.event.MouseEvent e)
The normalizeX and Y values are computed because the x/y position of the input MouseEvent is relative to the upper left corner of the button, whereas the x/y position of the button is relative to the upper left corner of the entire panel. Without these values, the mouseDragged logic would not work properly.
public void mouseDragged(java.awt.event.MouseEvent e)
public void mouseReleased(java.awt.event.MouseEvent e)
Note that if the button is moved off of the canvas, a new canvas size is not recomputed. This could be done in a similar manner to the canvas size re-computation at the end of the DrawingCanvas.paintComponent method. Alternatively, the button could be kept from moving off of the visible canvas altogether by adding appropriate checking code within the mouseDragged method.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |