Java 8 MouseEvent - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 MouseEvent class.

This code example shows how to use the following methods:getX, getY
				float mouseX = event.getX() - KNOB_WIDTH / 2 - border;
				setValue(sliderMin + (sliderMax - sliderMin) * Math.max(0, Math.min(width, mouseX)) / width);
			} 
 
			public void mouseMoved (MouseEvent event) {
				int mouseX = event.getX();
				int mouseY = event.getY();
 
			} 
		}); 
	} 
 
	protected void paintComponent (Graphics graphics) {
		super.paintComponent(graphics);
 
		Graphics2D g = (Graphics2D)graphics;
		int width = getWidth();
		int height = getHeight();
 
		g.setColor(bgColor);
8
CodeRank
This code example shows how to use the following methods:getID, getModifiers, getWhen, getButton, getClickCount
        } 
 
        public void mouseDragged(MouseEvent e) {
            isDragging = true;
            JComponent c = ColorWell.this;
            Point pt = e.getPoint();
            JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(c);
            pt = SwingUtilities.convertPoint(c, pt, frame.getContentPane());
            MouseEvent newEvent = new MouseEvent(colorPicker, e.getID(), e.getWhen(), e.getModifiers(), (int) pt.getX(), (int) pt.getY(), e.getClickCount(), e.isPopupTrigger(), e.getButton());
            colorPicker.dispatchEvent(newEvent);
        } 
 
        public void mouseMoved(MouseEvent e) {
        } 
 
        public void mousePressed(MouseEvent e) {
            isDragging = false;
            JComponent c = ColorWell.this;
            JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(c);
            if (frame == null) return;
8
CodeRank
This code example shows how to use the following methods:getID, getComponent, getWhen, getButton, getClickCount
        this.cellHeight = cellHeight;
        this.listener = listener;
    } 
 
    private MouseEvent translateToGrid(MouseEvent e) {
        int x = e.getX() / cellWidth;
        int y = e.getY() / cellHeight;
        return new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), e.getModifiersEx(), x, y, e.getClickCount(), e.isPopupTrigger(), e.getButton());
    } 
 
    @Override 
    public void mouseClicked(MouseEvent e) {
        listener.mouseClicked(translateToGrid(e));
    } 
 
    @Override 
    public void mousePressed(MouseEvent e) {
        listener.mousePressed(translateToGrid(e));
    } 
 
7
CodeRank
This code example shows how to use the following methods:getX, getY
        public void mousePressed(MouseEvent e) {
            if (!tabPane.isEnabled()) {
                return; 
            } 
 
            tabPressed = tabForCoordinate(tabPane, e.getX(), e.getY());
            if (tabPressed != -1) {
                tabPane.repaint(getTabBounds(tabPane, tabPressed));
            } 
        } 
 
        @Override 
        public void mouseReleased(MouseEvent e) {
            int oldTabPressed = tabPressed;
            tabPressed = -1;
            if (oldTabPressed != -1) {
                tabPane.repaint(getTabBounds(tabPane, oldTabPressed));
            } 
        } 
    } 
8
CodeRank
This code example shows how to use the following methods:getPoint, getX, getY
      } 
 
      @Override 
      public void mouseMoved(MouseEvent e) {
         if (running){
            Debug.info("moved to: " + e.getX() + "," + e.getY());     
 
            if (selecting)
               q = e.getPoint();
         } 
      } 
 
      @Override 
      public void mousePressed(MouseEvent e) {
         if (running){
            Debug.info("pressed at: " + e.getX() + "," + e.getY());     
 
            selecting = true;
            p = e.getPoint();
            q = e.getPoint();         
7
CodeRank
This code example shows how to use the following methods:getX, getY
    //---------------------------------------------------------------------- 
    // MouseListener Implementation 
 
    public void mousePressed( final MouseEvent e )
    { 
        if ( isMouseButtonPressed( e, myButtonDownMask ) )
        { 
            myOldX = e.getX();
            myOldY = e.getY();
 
            getCursorChanger().setCursor( this, null );
        } 
    } 
 
 
    public void mouseReleased( final MouseEvent e )
    { 
        if ( e.getButton() == myButton )
        { 
            getCursorChanger().resetCursor( this );
7
CodeRank
This code example shows how to use the following methods:isConsumed, getClickCount
            System.err.println("MOUSE AWT RELEASED ["+pressed+"]: "+prefix+", "+e);
        } 
    } 
 
    public synchronized void mouseClicked(final java.awt.event.MouseEvent e) {
        mouseClicked+=e.getClickCount();
        if(e.isConsumed()) {
            consumed++;
        } 
        queue.add(e);
        if( verbose ) {
            System.err.println("MOUSE AWT CLICKED ["+mouseClicked+"]: "+prefix+", "+e);
        } 
    } 
 
    public String toString() { return prefix+"[pressed "+pressed+", clicked "+mouseClicked+", consumed "+consumed+"]"; }
} 
 
7
CodeRank
This code example shows how to use the following methods:getComponent, getX, getY
     
    /** 
     * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) 
     */ 
    public void mousePressed(MouseEvent e) {
        if ( UILib.isButtonPressed(e, m_button) ) {
            e.getComponent().setCursor(
                Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
            m_xDown = e.getX();
            m_yDown = e.getY();
        } 
    } 
     
    /** 
     * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) 
     */ 
    public void mouseDragged(MouseEvent e) {
        if ( UILib.isButtonPressed(e, m_button) ) {
            Display display = (Display)e.getComponent();
            int x = e.getX(),   y = e.getY();
7
CodeRank
This code example shows how to use the following methods:getComponent, getX, getY
     
    /** 
     * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) 
     */ 
    public void mouseDragged(MouseEvent e) {
        if ( UILib.isButtonPressed(e, m_button) ) {
            int dy = e.getY() - down.y;
            int dx = e.getX() - down.x;
            double angle = Math.atan2(dy, dx);
             
            // only rotate once the base angle has been established 
            if ( !Double.isNaN(baseAngle) ) {
                Display display = (Display)e.getComponent();
                display.rotate(down, angle-baseAngle);
            } 
            baseAngle = angle;
        } 
    } 
     
    /** 
7
CodeRank
This code example shows how to use the following methods:getID, getWhen, isControlDown, getButton
	public void mouseExited(MouseEvent e) {
	} 
 
	private void handleButton(MouseEvent e) {
		byte state;
		switch (e.getID()) {
			case MouseEvent.MOUSE_PRESSED:
				state = 1;
				break; 
			case MouseEvent.MOUSE_RELEASED:
				state = 0;
				break; 
			default: 
				throw new IllegalArgumentException("Not a valid event ID: " + e.getID());
		} 
		byte button;
		switch (e.getButton()) {
			case MouseEvent.NOBUTTON:
				// Nothing to do, so return 
				return; 

7
CodeRank
See Code Examples for Java 8 MouseEvent Methods: