/ Published in: Java
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import java.awt.Component; import java.awt.Rectangle; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class RubberBand { private int maxWidth; private int maxHeight; this.component = component; addListeners(); } private void addListeners() { reactOnMouseDragged(event); } }); reactOnMousePressed(event); } reactOnMouseClicked(); } }); } public int getX() { return rectangle.width >= 0 ? rectangle.x : (rectangle.x + rectangle.width); } public int getY() { return rectangle.height >= 0 ? rectangle.y : (rectangle.y + rectangle.height); } public int getWidth() { } public int getHeight() { } rubberBandListeners.add(rubberBandListener); } public void notifyRubberBandListeners() { while (iterator.hasNext()) { } } public void kill() { rectangle = null; notifyRubberBandListeners(); } if (rectangle == null) createRubberBand(0,0); rectangle.width = x - rectangle.x; rectangle.height = y - rectangle.y; notifyRubberBandListeners(); } private void createRubberBand(int x, int y) { } createRubberBand(event.getX(), event.getY()); notifyRubberBandListeners(); } private void reactOnMouseClicked() { kill(); } public boolean isActive() { return rectangle != null; } public void setMaxBounds(int width, int height) { this.maxWidth = width; this.maxHeight = height; } }