Example usage for java.awt.event MouseEvent getY

List of usage examples for java.awt.event MouseEvent getY

Introduction

In this page you can find the example usage for java.awt.event MouseEvent getY.

Prototype

public int getY() 

Source Link

Document

Returns the vertical y position of the event relative to the source component.

Usage

From source file:LayeredPaneDemo.java

public void mouseMoved(MouseEvent e) {
    dukeLabel.setLocation(e.getX() - XFUDGE, e.getY() - YFUDGE);
}

From source file:ShapeMover.java

public void mousePressed(MouseEvent e) {
    preX = rect.x - e.getX();// w ww  . j a va 2  s . c  o  m
    preY = rect.y - e.getY();

    if (rect.contains(e.getX(), e.getY()))
        updateLocation(e);
    else {
        ShapeMover.label.setText("Drag it.");
        pressOut = true;
    }
}

From source file:UndoManagerDemo.java

public UndoManagerDemo() {
    super("Undo/Redo Demo");

    undoButton.setEnabled(false);/* ww  w  .j  a  v  a  2s  .  c o m*/
    redoButton.setEnabled(false);

    JPanel buttonPanel = new JPanel(new GridLayout());
    buttonPanel.add(undoButton);
    buttonPanel.add(redoButton);

    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    getContentPane().add(canvas, BorderLayout.CENTER);

    canvas.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            Point point = new Point(e.getX(), e.getY());
            pointVector.addElement(point);

            undoManager.undoableEditHappened(
                    new UndoableEditEvent(canvas, new UndoablePaintSquare(point, pointVector)));

            undoButton.setText(undoManager.getUndoPresentationName());
            redoButton.setText(undoManager.getRedoPresentationName());
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
            canvas.repaint();
        }
    });

    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.undo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            canvas.repaint();
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.redo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            canvas.repaint();
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
        }
    });

    setSize(400, 300);
    setVisible(true);
}

From source file:components.LayeredPaneDemo2.java

public void mouseMoved(MouseEvent e) {
    dukeLabel.setLocation(e.getX() - dukeLabel.getWidth() / 2, e.getY() - dukeLabel.getHeight() / 2);
}

From source file:com.cburch.draw.tools.LineTool.java

@Override
public void mouseDragged(Canvas canvas, MouseEvent e) {
    updateMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());
}

From source file:components.ScrollablePicture.java

public void mouseDragged(MouseEvent e) {
    //The user is dragging us, so scroll!
    Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1);
    scrollRectToVisible(r);//from   w  ww .  ja  v  a2s.  c  o m
}

From source file:lu.lippmann.cdb.common.gui.DragAndDroppablePieChartPanel.java

/**
 * {@inheritDoc}//from   ww w  . ja v  a2  s .c o  m
 */
@Override
public void mousePressed(MouseEvent e) {
    super.mousePressed(e);
    final ChartEntity entity = getEntityForPoint(e.getX(), e.getY());
    if (entity instanceof PieSectionEntity) {
        source = (PieSectionEntity) entity;
    }
    released = false;
}

From source file:com.cburch.draw.tools.LineTool.java

@Override
public void mousePressed(Canvas canvas, MouseEvent e) {
    int x = e.getX();
    int y = e.getY();
    int mods = e.getModifiersEx();
    if ((mods & InputEvent.CTRL_DOWN_MASK) != 0) {
        x = canvas.snapX(x);/*w w w.j  av  a 2s . c om*/
        y = canvas.snapY(y);
    }
    Location loc = Location.create(x, y);
    mouseStart = loc;
    mouseEnd = loc;
    lastMouseX = loc.getX();
    lastMouseY = loc.getY();
    active = canvas.getModel() != null;
    repaintArea(canvas);
}

From source file:lu.lippmann.cdb.common.gui.DragAndDroppablePieChartPanel.java

/**
 * {@inheritDoc}//from   w  ww .  ja va  2 s  . co  m
 */
@Override
public void mouseReleased(MouseEvent e) {
    super.mouseReleased(e);
    final ChartEntity entity = getEntityForPoint(e.getX(), e.getY());
    if (entity instanceof PieSectionEntity) {
        final PieSectionEntity target = ((PieSectionEntity) entity);
        if (source != null) {
            if (target.getSectionIndex() != source.getSectionIndex()) {
                listener.onAction(new Integer[] { source.getSectionIndex(), target.getSectionIndex() });
            }
        }
    }
    released = true;
    repaint();
}

From source file:com.cburch.draw.tools.LineTool.java

@Override
public void mouseReleased(Canvas canvas, MouseEvent e) {
    if (active) {
        updateMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());
        Location start = mouseStart;
        Location end = mouseEnd;/*from w  ww .ja v a  2s.c o m*/
        CanvasObject add = null;
        if (!start.equals(end)) {
            active = false;
            CanvasModel model = canvas.getModel();
            Location[] ends = { start, end };
            List<Location> locs = UnmodifiableList.decorate(Arrays.asList(ends));
            add = attrs.applyTo(new Poly(false, locs));
            add.setValue(DrawAttr.PAINT_TYPE, DrawAttr.PAINT_STROKE);
            canvas.doAction(new ModelAddAction(model, add));
            repaintArea(canvas);
        }
        canvas.toolGestureComplete(this, add);
    }
}