Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public AnimationPanel() {
- // remove these lines
- // Insets insets = getInsets();
- // int marginWidth = getWidth() - insets.left - insets.right;
- // int marginHeight = getHeight() - insets.top - insets.bottom;
- // s = new MovingRectangle(10, 10, currentWidth, currentHeight, marginWidth, marginHeight, currentPath);
- //
- popup = new JPopupMenu(); //create the popup menu
- makePopupMenu();
- // add the mouse event to handle popup menu and create new shape
- addMouseListener( new MouseAdapter() {
- public void mousePressed(MouseEvent e) {
- maybeShowPopup(e);
- }
- public void mouseReleased(MouseEvent e) {
- maybeShowPopup(e);
- }
- private void maybeShowPopup(MouseEvent e) {
- if (e.isPopupTrigger()) {
- popup.show(e.getComponent(), e.getX(), e.getY());
- }
- }
- public void mouseClicked( MouseEvent e ) {
- if (animationThread != null) { // if the animation has started, then
- boolean found = false;
- for (MovingShape sh : s) {
- if ( sh.contains( e.getPoint()) ) { // if the mousepoint is within a shape, then set the shape to be selected/deselected
- found = true;
- sh.setSelected( ! sh.isSelected() );
- }
- }
- if (! found) createNewShape(e.getX(), e.getY()); // if the mousepoint is not within a shape, then create a new one according to the mouse position
- }
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement