当前位置: 首页>>代码示例>>Java>>正文


Java MouseEvent.getX方法代码示例

本文整理汇总了Java中java.awt.event.MouseEvent.getX方法的典型用法代码示例。如果您正苦于以下问题:Java MouseEvent.getX方法的具体用法?Java MouseEvent.getX怎么用?Java MouseEvent.getX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.event.MouseEvent的用法示例。


在下文中一共展示了MouseEvent.getX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handlePopupMenu

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
private void handlePopupMenu (MouseEvent e) {
    if (!e.isPopupTrigger()) {
        return;
    }
    final JTree tree = (JTree) e.getSource();
    Point p = e.getPoint();
    int x = e.getX();
    int y = e.getY();
    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);
    
    if (path != null) {
        DirectoryNode node = (DirectoryNode) path.getLastPathComponent();
        ((DirectoryTreeModel) tree.getModel()).nodeChanged(node);
        if(!fileChooser.getFileSystemView().isFileSystem(node.getFile())) {
            return;
        }

        tree.setSelectionPath(path);
        popupMenu.show(tree, x, y);
    }            
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:DirectoryChooserUI.java

示例2: isWithin

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
private boolean isWithin(InstanceState state, MouseEvent e) {
	Bounds bds = state.getInstance().getBounds();
	int cx = bds.getX() + bds.getWidth() / 2;
	int cy = bds.getY() + bds.getHeight() / 2;
	int dx = e.getX() - cx;
	int dy = e.getY() - cy;
	return dx * dx + dy * dy <= 60;
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:9,代码来源:SubcircuitPoker.java

示例3: mousePressed

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
public void mousePressed(MouseEvent ev) {
    if (ev.isPopupTrigger()) {
        int x = ev.getX();
        int y = ev.getY();
        TreePath path = view.getClosestPathForLocation(x, y);
        if (path != null) {
            LookTreeNode n = (LookTreeNode)path.getLastPathComponent();
            clicked = new WeakReference<LookTreeNode>(n);
            @SuppressWarnings("unchecked")
            Action[] actions = n.getLook().getActions(n.getData(), n.getLookup() );
            // XXX handle multiselects...
            Node selection = makeNode( n );
            Lookup context = Lookups.fixed(new Object[] {selection, actionMap});
            JPopupMenu menu = Utilities.actionsToPopup(actions, context);
            menu.show(view, x, y);
            // XXX selection does not appear to be collected... do we need to
            // also destroy the popup menu?
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:PopupHandler.java

示例4: mouseDragged

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
@Override
public void mouseDragged(MouseEvent e) {
  int mx = e.getX() - xInset;
  int my = e.getY() - yInset;

  int gridX = mx / cellSize;
  int gridY = my / cellSize;

  if (gridX < sprite.getWidth() && gridY < sprite.getHeight() && gridX >= 0 && gridY >= 0) {
    if (SwingUtilities.isLeftMouseButton(e)) {
      sprite.setBit(gridX, gridY);
    } else {
      sprite.resetBit(gridX, gridY);
    }
  }
  repaint();
  parent.dispatchEvent(e);
}
 
开发者ID:ThunderSOS,项目名称:ZXSprite,代码行数:19,代码来源:SpriteToggler.java

示例5: mousePressed

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
	boolean wire = updateLocation(canvas, e);
	Location oldWireLoc = wireLoc;
	wireLoc = NULL_LOCATION;
	lastX = Integer.MIN_VALUE;
	if (wire) {
		current = wiring;
		Selection sel = canvas.getSelection();
		Circuit circ = canvas.getCircuit();
		Collection<Component> selected = sel.getAnchoredComponents();
		ArrayList<Component> suppress = null;
		for (Wire w : circ.getWires()) {
			if (selected.contains(w)) {
				if (w.contains(oldWireLoc)) {
					if (suppress == null)
						suppress = new ArrayList<Component>();
					suppress.add(w);
				}
			}
		}
		sel.setSuppressHandles(suppress);
	} else {
		current = select;
	}
	pressX = e.getX();
	pressY = e.getY();
	current.mousePressed(canvas, g, e);
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:30,代码来源:EditTool.java

示例6: mouseDragged

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
public void mouseDragged(MouseEvent e) {
	xTile = e.getX() / 16;
	yTile = e.getY() / 16;

	cursorPosition.setText("Cursor position: ("+xTile+", "+yTile+")");
	
	level.setBlock(xTile, yTile, tilePicker.pickedTile);
	levelRenderer.repaint(xTile - 1, yTile - 1, 3, 3);

	repaint();
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:12,代码来源:LevelEditView.java

示例7: mousePressed

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
@Override
public void mousePressed(MouseEvent e) {
    if (isAllowed(e)) {
        this.pressX = e.getX();
        this.pressY = e.getY();
        this.bounds.setBounds(this.pressX, this.pressY, 0, 0);
        this.active = true;
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:10,代码来源:JGraphUI.java

示例8: WidgetMouseEvent

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
/**
 * Creates a mouse event.
 * @param id the event id
 * @param event the Swing event
 */
public WidgetMouseEvent(long id, MouseEvent event) {
    this.id = id;
    this.event = event;
    x = event.getX();
    y = event.getY();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:WidgetAction.java

示例9: mouseMoved

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
/**
 * Implementation of the MouseMotionListener's method
 *
 * @param e  the event.
 */
public void mouseMoved(MouseEvent e) {

    if (this.horizontalAxisTrace) {
        drawHorizontalAxisTrace(e.getX());
    }

    if (this.verticalAxisTrace) {
        drawVerticalAxisTrace(e.getY());
    }

    if (this.chartMouseListeners.isEmpty()) {
        return;
    }

    Insets insets = getInsets();
    int x = (int) ((e.getX() - insets.left) / this.scaleX);
    int y = (int) ((e.getY() - insets.top) / this.scaleY);

    ChartEntity entity = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
        }
    }
    ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);

    Iterator iterator = this.chartMouseListeners.iterator();
    while (iterator.hasNext()) {
        ChartMouseListener listener = (ChartMouseListener) iterator.next();
        listener.chartMouseMoved(event);
    }

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:40,代码来源:ChartPanel.java

示例10: mouseMoved

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
public void mouseMoved(MouseEvent e) {
    mouseX = e.getX();
    mouseY = e.getY();

    if (selectionMode == SELECTION_NONE) setSelectionBounds(null);
    else setSelectionBounds(mouseX, mouseY, 0, 0);

    updateHighlightedItems();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:ChartSelectionManager.java

示例11: isCellEditable

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
/**
 * Overridden to return false, and if the event is a mouse event it is
 * forwarded to the tree.
 * <p>
 * The behavior for this is debatable, and should really be offered as a
 * property. By returning false, all keyboard actions are implemented in
 * terms of the table. By returning true, the tree would get a chance to
 * do something with the keyboard events. For the most part this is ok.
 * But for certain keys, such as left/right, the tree will
 * expand/collapse where as the table focus should really move to a
 * different column. Page up/down should also be implemented in terms of
 * the table. By returning false this also has the added benefit that
 * clicking outside of the bounds of the tree node, but still in the
 * tree column will select the row, whereas if this returned true that
 * wouldn't be the case.
 * <p>
 * By returning false we are also enforcing the policy that the tree
 * will never be editable (at least by a key sequence).
 */
public boolean isCellEditable(EventObject e) {
    if (e instanceof MouseEvent) {
        for (int counter = getColumnCount() - 1; counter >= 0; counter--) {
            if (getColumnClass(counter) == TreeTableModel.class) {
                MouseEvent me = (MouseEvent) e;
                MouseEvent newME = new MouseEvent(tree, me.getID(), me
                        .getWhen(), me.getModifiers(), me.getX()
                        - getCellRect(0, counter, true).x, me.getY(),
                        me.getClickCount(), me.isPopupTrigger());
                tree.dispatchEvent(newME);
                break;
            }
        }
    }
    return false;
}
 
开发者ID:ser316asu,项目名称:Neukoelln_SER316,代码行数:36,代码来源:TaskTable.java

示例12: isCellEditable

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
/**
 * Overridden to return false, and if the event is a mouse event it is
 * forwarded to the tree.
 * <p>
 * The behavior for this is debatable, and should really be offered as a
 * property. By returning false, all keyboard actions are implemented in
 * terms of the table. By returning true, the tree would get a chance to
 * do something with the keyboard events. For the most part this is ok.
 * But for certain keys, such as left/right, the tree will
 * expand/collapse where as the table focus should really move to a
 * different column. Page up/down should also be implemented in terms of
 * the table. By returning false this also has the added benefit that
 * clicking outside of the bounds of the tree node, but still in the
 * tree column will select the row, whereas if this returned true that
 * wouldn't be the case.
 * <p>
 * By returning false we are also enforcing the policy that the tree
 * will never be editable (at least by a key sequence).
 */
public boolean isCellEditable(EventObject e) {
	if (e instanceof MouseEvent) {
		for (int counter = getColumnCount() - 1; counter >= 0; counter--) {
			if (getColumnClass(counter) == TreeTableModel.class) {
				MouseEvent me = (MouseEvent) e;
				MouseEvent newME = new MouseEvent(tree, me.getID(), me
						.getWhen(), me.getModifiers(), me.getX()
						- getCellRect(0, counter, true).x, me.getY(),
						me.getClickCount(), me.isPopupTrigger());
				tree.dispatchEvent(newME);
				break;
			}
		}
	}
	return false;
}
 
开发者ID:ser316asu,项目名称:SER316-Aachen,代码行数:36,代码来源:JTreeTable.java

示例13: mousePressed

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
@Override
public void mousePressed(MouseEvent e) {
    prevx = e.getX();
    prevy = e.getY();
    e.consume();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:XYZApp.java

示例14: mouseDragged

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
/**
 * Set the models value to the position of the top/left
 * of the thumb relative to the origin of the track.
 */
public void mouseDragged(final MouseEvent e) {
    int thumbMiddle = 0;

    if (!slider.isEnabled()) return;

    currentMouseX = e.getX();
    currentMouseY = e.getY();

    if (!fIsDragging) return;

    slider.setValueIsAdjusting(true);

    switch (slider.getOrientation()) {
        case SwingConstants.VERTICAL:
            final int halfThumbHeight = thumbRect.height / 2;
            int thumbTop = e.getY() - offset;
            int trackTop = trackRect.y;
            int trackBottom = trackRect.y + (trackRect.height - 1);
            final int vMax = yPositionForValue(slider.getMaximum() - slider.getExtent());

            if (drawInverted()) {
                trackBottom = vMax;
            } else {
                trackTop = vMax;
            }
            thumbTop = Math.max(thumbTop, trackTop - halfThumbHeight);
            thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight);

            setThumbLocation(thumbRect.x, thumbTop);

            thumbMiddle = thumbTop + halfThumbHeight;
            slider.setValue(valueForYPosition(thumbMiddle));
            break;
        case SwingConstants.HORIZONTAL:
            final int halfThumbWidth = thumbRect.width / 2;
            int thumbLeft = e.getX() - offset;
            int trackLeft = trackRect.x;
            int trackRight = trackRect.x + (trackRect.width - 1);
            final int hMax = xPositionForValue(slider.getMaximum() - slider.getExtent());

            if (drawInverted()) {
                trackLeft = hMax;
            } else {
                trackRight = hMax;
            }
            thumbLeft = Math.max(thumbLeft, trackLeft - halfThumbWidth);
            thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth);

            setThumbLocation(thumbLeft, thumbRect.y);

            thumbMiddle = thumbLeft + halfThumbWidth;
            slider.setValue(valueForXPosition(thumbMiddle));
            break;
        default:
            return;
    }

    // enable live snap-to-ticks <rdar://problem/3165310>
    if (slider.getSnapToTicks()) {
        calculateThumbLocation();
        setThumbLocation(thumbRect.x, thumbRect.y); // need to call to refresh the repaint region
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:68,代码来源:AquaSliderUI.java

示例15: mousePressed

import java.awt.event.MouseEvent; //导入方法依赖的package包/类
public void mousePressed(final MouseEvent e) {
    if (!slider.isEnabled()) return;

    // We should recalculate geometry just before
    // calculation of the thumb movement direction.
    // It is important for the case, when JSlider
    // is a cell editor in JTable. See 6348946.
    calculateGeometry();

    final boolean firstClick = (currentMouseX == -1) && (currentMouseY == -1);

    currentMouseX = e.getX();
    currentMouseY = e.getY();

    if (slider.isRequestFocusEnabled()) {
        slider.requestFocus();
    }

    boolean isMouseEventInThumb = thumbRect.contains(currentMouseX, currentMouseY);

    // we don't want to move the thumb if we just clicked on the edge of the thumb
    if (!firstClick || !isMouseEventInThumb) {
        slider.setValueIsAdjusting(true);

        switch (slider.getOrientation()) {
            case SwingConstants.VERTICAL:
                slider.setValue(valueForYPosition(currentMouseY));
                break;
            case SwingConstants.HORIZONTAL:
                slider.setValue(valueForXPosition(currentMouseX));
                break;
        }

        slider.setValueIsAdjusting(false);

        isMouseEventInThumb = true; // since we just moved it in there
    }

    // Clicked in the Thumb area?
    if (isMouseEventInThumb) {
        switch (slider.getOrientation()) {
            case SwingConstants.VERTICAL:
                offset = currentMouseY - thumbRect.y;
                break;
            case SwingConstants.HORIZONTAL:
                offset = currentMouseX - thumbRect.x;
                break;
        }

        fIsDragging = true;
        return;
    }

    fIsDragging = false;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:56,代码来源:AquaSliderUI.java


注:本文中的java.awt.event.MouseEvent.getX方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。