本文整理汇总了Java中java.awt.event.MouseEvent类的典型用法代码示例。如果您正苦于以下问题:Java MouseEvent类的具体用法?Java MouseEvent怎么用?Java MouseEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MouseEvent类属于java.awt.event包,在下文中一共展示了MouseEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: maybeShowPopup
import java.awt.event.MouseEvent; //导入依赖的package包/类
private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
JPopupMenu popupMenu = new JPopupMenu();
popupMenu.setFocusable(false);
popupMenu.add(jMenuItemUndo);
popupMenu.add(jMenuItemRedo);
popupMenu.addSeparator();
popupMenu.add(jMenuItemCut);
popupMenu.add(jMenuItemCopy);
popupMenu.add(jMenuItemPaste);
popupMenu.addSeparator();
if (jMenuItemInsCell.getAction().isEnabled()) {
popupMenu.add(jMenuItemInsCell);
jMenuItemInsCell.setEnabled(true);
popupMenu.add(jMenuItemInsRow);
jMenuItemInsRow.setEnabled(true);
popupMenu.addSeparator();
}
popupMenu.add(jMenuItemProp);
popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
示例2: initialize
import java.awt.event.MouseEvent; //导入依赖的package包/类
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 800, 450);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
final JButton btnNewButton = new JButton("\u62CD\u7167");
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
flag = 1;// ��̬��������Ϊ1���Ӷ����°�ťʱ��ֹͣ����ͷ�ĵ���
}
});
btnNewButton.setBounds(33, 13, 113, 27);
frame.getContentPane().add(btnNewButton);
label = new JLabel("");
label.setBounds(0, 0, 800, 450);
frame.getContentPane().add(label);
}
示例3: mousePressed
import java.awt.event.MouseEvent; //导入依赖的package包/类
@Override
public void mousePressed(final MouseEvent e)
{
if( e.getButton() == MouseEvent.BUTTON3 )
{
setSelectionPath(getPathForLocation(e.getX(), e.getY()));
}
final WorkflowNode node = getSelectedNode();
final boolean canedit = node != null && node.getParent() != model.getRoot();
visible = (node == null && model.getRootNode() == null) || (node != null && node.canAddChildren());
add.setVisible(visible);
edit.setVisible(canedit);
remove.setVisible(canedit);
visible |= node != null;
}
示例4: mouseReleased
import java.awt.event.MouseEvent; //导入依赖的package包/类
/**
* Mouse events are first translated into map coordinates.
* Then the event is forwarded to the top MouseListener in the
* stack, if any, otherwise forwarded to all LocalMouseListeners.
*
* @see #pushMouseListener
* @see #popMouseListener
* @see #addLocalMouseListener
*/
public void mouseReleased(MouseEvent e) {
Point p = e.getPoint();
p.translate(theMap.getX(), theMap.getY());
if (theMap.getBounds().contains(p)) {
if (!mouseListenerStack.isEmpty()) {
p = mapCoordinates(e.getPoint());
e.translatePoint(p.x - e.getX(), p.y - e.getY());
mouseListenerStack.get(mouseListenerStack.size()-1).mouseReleased(e);
}
else if (multicaster != null) {
p = mapCoordinates(e.getPoint());
e.translatePoint(p.x - e.getX(), p.y - e.getY());
multicaster.mouseReleased(e);
}
// Request Focus so that keyboard input will be recognized
theMap.requestFocus();
}
// Clicking with mouse always repaints the map
clearFirst = true;
theMap.repaint();
activeMap = this;
}
示例5: handlePopup
import java.awt.event.MouseEvent; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void handlePopup(MouseEvent e) {
final VisualizationViewer<V,E> vv =
(VisualizationViewer<V,E>)e.getSource();
Point2D p = e.getPoint();
GraphElementAccessor<V,E> pickSupport = vv.getPickSupport();
if(pickSupport != null) {
final V v = pickSupport.getVertex(vv.getGraphLayout(), p.getX(), p.getY());
if(v != null) {
updateVertexMenu(v, networkPanel, p);
vertexPopup.show(vv, e.getX(), e.getY());
} else {
final E edge = pickSupport.getEdge(vv.getGraphLayout(), p.getX(), p.getY());
if(edge != null) {
updateEdgeMenu(edge, networkPanel, p);
edgePopup.show(vv, e.getX(), e.getY());
}
}
}
}
示例6: mouseMoved
import java.awt.event.MouseEvent; //导入依赖的package包/类
@Override
// Track mouse on movement
public void mouseMoved(MouseEvent e) {
int x = e.getX();
int y = e.getY();
int height = this.getHeight();
// Detects if mouse is within button panel
if(x >= 10 && x <= 332 && y >= (height-96) && y <= (height-6)) {
btnHover = true;
}
else {
btnHover = false;
}
repaint();
}
示例7: mousePressed
import java.awt.event.MouseEvent; //导入依赖的package包/类
@Override
public void mousePressed(MouseEvent e) {
if (e.isShiftDown()) return;
e.getComponent().requestFocus();
if (e.getButton() == MouseEvent.BUTTON1) {
dragAnim.stop();
bDragging = true;
dragMem = e.getPoint();
dragWhen = e.getWhen();
}
}
示例8: mouseDragged
import java.awt.event.MouseEvent; //导入依赖的package包/类
public void mouseDragged(MouseEvent e) {
mouseX = e.getX();
mouseY = e.getY();
if (SwingUtilities.isLeftMouseButton(e)) {
mouseB = 1;
}
if (SwingUtilities.isRightMouseButton(e)) {
mouseB = 3;
}
MouseDraggedEvent event = new MouseDraggedEvent(e.getX(), e.getY(), mouseB);
try {
eventListener.onEvent(event);
} catch (Exception ex) {}
}
示例9: mousePressed
import java.awt.event.MouseEvent; //导入依赖的package包/类
@Override
public void mousePressed(MouseEvent evt) {
TreePath path = getPathForLocation(evt.getX(), evt.getY());
if (path != null) {
if (evt.getButton() == MouseEvent.BUTTON3 && !isRowSelected(getRowForPath(path))) {
setSelectionPath(path);
}
DisplayKind toDisplay = null;
Object lastComponent = path.getLastPathComponent();
if (lastComponent instanceof RuleTreeNode) {
toDisplay = DisplayKind.RULE;
} else if (lastComponent instanceof RecipeTreeNode) {
toDisplay = DisplayKind.CONTROL;
} else if (lastComponent instanceof MatchTreeNode
&& getSimulatorModel().getDisplay() != DisplayKind.LTS) {
toDisplay = DisplayKind.STATE;
}
if (evt.getClickCount() == 1 && toDisplay != null) {
getSimulatorModel().setDisplay(toDisplay);
} else if (evt.getClickCount() == 2 && toDisplay != null) {
if (toDisplay.hasResource()) {
getActions().getEditAction(toDisplay.getResource())
.execute();
}
}
}
maybeShowPopup(evt);
}
示例10: onContentMouseReleasedEvent
import java.awt.event.MouseEvent; //导入依赖的package包/类
protected void onContentMouseReleasedEvent(MouseEvent e)
{
Point mousePoint = e.getPoint();
mousePoint.x -= 0.5F;
int index = this.textContent.viewToModel(mousePoint);
if (index == -1) return;
StyledDocument doc = this.getDocument();
Element element = doc.getCharacterElement(index);
LinkHandler handler = LinkHandler.getLinkHandler(element.getAttributes());
if (handler != null)
{
int begin = element.getStartOffset();
int end = element.getEndOffset();
String string = null;
try
{
string = doc.getText(begin, end - begin);
}
catch (BadLocationException ex)
{
ex.printStackTrace();
}
if (string == null) return;
handler.execute(this, doc, string, begin, end, element);
}
}
示例11: installFocusHandler
import java.awt.event.MouseEvent; //导入依赖的package包/类
/**
* installs a handler to set the focus to the container.
*/
protected void installFocusHandler()
{
graphControl.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
if (!hasFocus())
{
requestFocus();
}
}
});
}
示例12: mousePressed
import java.awt.event.MouseEvent; //导入依赖的package包/类
@Override
public void mousePressed(MouseEvent e) {
if (e.isConsumed() || (!e.isPopupTrigger()))
return;
int row = table.rowAtPoint(e.getPoint());
int column = table.columnAtPoint(e.getPoint());
table.changeSelection(row, column, false, false);
AddressBookEntry entry = entries.get(row);
JPopupMenu menu = new JPopupMenu();
JMenuItem sendCash = new JMenuItem("Send ZEN to "+entry.name);
sendCash.addActionListener(new SendCashActionListener());
menu.add(sendCash);
JMenuItem copyAddress = new JMenuItem("Copy address to clipboard");
copyAddress.addActionListener(new CopyToClipboardActionListener());
menu.add(copyAddress);
JMenuItem deleteEntry = new JMenuItem("Delete "+entry.name+" from contacts");
deleteEntry.addActionListener(new DeleteAddressActionListener());
menu.add(deleteEntry);
menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y);
e.consume();
}
示例13: getPixel
import java.awt.event.MouseEvent; //导入依赖的package包/类
private Point getPixel(MouseEvent e) {
if (canvas == null) {
return null;
}
Point p = canvas.getPixelFromMouseEvent(e);
if (canvas.wasMousePixelInsideChipBounds()) {
return p;
} else {
return null;
}
}
示例14: clickMouse
import java.awt.event.MouseEvent; //导入依赖的package包/类
@Override
public void clickMouse(ComponentOperator oper, int x, int y, int clickCount, int mouseButton,
int modifiers, Timeout mouseClick) {
moveMouse(oper, x, y);
dispatchEvent(oper.getSource(),
MouseEvent.MOUSE_ENTERED,
0, x, y, 0,
Operator.getDefaultMouseButton());
dispatchEvent(oper.getSource(),
MouseEvent.MOUSE_PRESSED,
modifiers, x, y, 1,
mouseButton);
for (int i = 1; i < clickCount; i++) {
dispatchEvent(oper.getSource(),
MouseEvent.MOUSE_RELEASED,
modifiers, x, y, i,
mouseButton);
dispatchEvent(oper.getSource(),
MouseEvent.MOUSE_CLICKED,
modifiers, x, y, i,
mouseButton);
dispatchEvent(oper.getSource(),
MouseEvent.MOUSE_PRESSED,
modifiers, x, y, i + 1,
mouseButton);
}
mouseClick.sleep();
dispatchEvent(oper.getSource(),
MouseEvent.MOUSE_RELEASED,
modifiers, x, y, clickCount,
mouseButton);
dispatchEvent(oper.getSource(),
MouseEvent.MOUSE_CLICKED,
modifiers, x, y, clickCount,
mouseButton);
exitMouse(oper);
}
示例15: mousePressed
import java.awt.event.MouseEvent; //导入依赖的package包/类
/**
* Invoked when a mouse button has been pressed on a component.
*/
@Override
public void mousePressed(MouseEvent e) {
events.clear();
if (mapDragOperationFromModifiers(e) != DnDConstants.ACTION_NONE) {
try {
motionThreshold = DragSource.getDragThreshold();
} catch (Exception exc) {
motionThreshold = 5;
}
appendEvent(e);
}
}