Java Reference
In-Depth Information
private class MouseHandler extends MouseInputAdapter {
@Override
public void mousePressed(MouseEvent e) {
// Check if the cursor is inside any marker
if(ctrlQuad.contains(e.getX(), e.getY())) {
selected = ctrlQuad;
}
else if(ctrlCubic1.contains(e.getX(), e.getY())) {
selected = ctrlCubic1;
}
else if(ctrlCubic2.contains(e.getX(), e.getY())) {
selected = ctrlCubic2;
}
}
@Override
public void mouseReleased(MouseEvent e) {
selected = null;
// Deselect any
selected marker
}
@Override
public void mouseDragged(MouseEvent e) {
if(selected != null) {
// If a marker is
selected
// Set the marker to current cursor position
selected.setLocation(e.getX(), e.getY());
pane.repaint();
// Redraw pane
contents
}
}
private Marker selected;
// Stores reference
to selected marker
}
Directory "CurveApplet 3 moving the control points"
You need to add two import statements to the beginning of the source file, one because you reference
the MouseInputAdapter class and the other because you refer to the MouseEvent class:
Search WWH ::




Custom Search