本文整理汇总了Java中java.awt.MouseInfo.getPointerInfo方法的典型用法代码示例。如果您正苦于以下问题:Java MouseInfo.getPointerInfo方法的具体用法?Java MouseInfo.getPointerInfo怎么用?Java MouseInfo.getPointerInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.MouseInfo
的用法示例。
在下文中一共展示了MouseInfo.getPointerInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawCursor
import java.awt.MouseInfo; //导入方法依赖的package包/类
/**
* Draws the cursor on the frame, if required.
*
* @param frame the frame to update
* @return the (potentially) updated frame
*/
protected BufferedImage drawCursor(BufferedImage frame) {
PointerInfo pointer;
if (m_CaptureMouse && (m_Cursor != null)) {
pointer = MouseInfo.getPointerInfo();
frame.getGraphics().drawImage(
m_Cursor,
(int) pointer.getLocation().getX() - m_X,
(int) pointer.getLocation().getY() - m_Y,
m_Cursor.getWidth(null),
m_Cursor.getHeight(null),
m_BackgroundColor,
null);
}
return frame;
}
示例2: createCurrent
import java.awt.MouseInfo; //导入方法依赖的package包/类
/**
* Create a mouse movement event as if the mouse just
* moved to its current position.
* @param c the base swing component to relativize the mouse location
* @return the mouse event
*/
public static UIMouse createCurrent(Component c) {
UIMouse m = new UIMouse();
m.type = UIMouse.Type.MOVE;
PointerInfo pointerInfo = MouseInfo.getPointerInfo();
if (pointerInfo != null) {
Point pm = pointerInfo.getLocation();
Point pc = new Point(0, 0);
try {
pc = c.getLocationOnScreen();
} catch (IllegalStateException ex) {
// ignored
}
m.x = pm.x - pc.x;
m.y = pm.y - pc.y;
}
return m;
}
示例3: checkMouseLocation
import java.awt.MouseInfo; //导入方法依赖的package包/类
/**
* Check if mouse location has changed from previous check.
*/
private static void checkMouseLocation() {
PointerInfo info = MouseInfo.getPointerInfo();
// This can sometimes be null, so check for it (e.g. when Windows' UAC
// screen is active)
if (info == null) {
return;
}
Point currentLocation = info.getLocation();
if (lastLocation != null && !lastLocation.equals(currentLocation)) {
lastMoved = System.currentTimeMillis();
triggerActivity();
}
lastLocation = currentLocation;
}
示例4: doLeftClick
import java.awt.MouseInfo; //导入方法依赖的package包/类
@Override
protected void doLeftClick(final Point point) throws InterruptedException {
// TODO non funziona
final PointerInfo a = MouseInfo.getPointerInfo();
final java.awt.Point b = a.getLocation();
final int xOrig = (int) b.getX();
final int yOrig = (int) b.getY();
try {
final Point p = clientToScreen(point);
robot.mouseMove(p.x(), p.y());
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
} finally {
robot.mouseMove(xOrig, yOrig);
}
}
示例5: buildPopup
import java.awt.MouseInfo; //导入方法依赖的package包/类
private JPopupMenu buildPopup(Map<Class, StepDescription> stepMap) {
JPopupMenu pop = new JPopupMenu();
JMenu add = new JMenu("Add Transformer");
JMenuItem labelMenuItem = new JMenuItem("Add Label");
//figure out where the user clicked
PointerInfo pi = MouseInfo.getPointerInfo();
Point startLocation = pi.getLocation();
SwingUtilities.convertPointFromScreen(startLocation,this);
labelMenuItem.addActionListener(new AddLabelAction(this, startLocation));
pop.add(add);
pop.add(labelMenuItem);
StepDescription[] sds = stepMap.values().toArray(new StepDescription[0]);
Arrays.sort(sds);
for (StepDescription sd : sds) {
JMenuItem item = new JMenuItem(sd.getName(), sd.getIcon());
item.addActionListener(new AddStepActon(sd.getLogicClass()));
add.add(item);
}
return pop;
}
示例6: init
import java.awt.MouseInfo; //导入方法依赖的package包/类
public void init() {
frame = new JFrame("Recursive Directory Removal Pro "+RdProUI.version);
frame.setContentPane(layoutPanel1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
/*position it*/
//frame.setLocationRelativeTo(null); // *** this will center your app ***
PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
int x = (int) b.getX();
int y = (int) b.getY();
frame.setLocation(x + 100, y);
btnEditRootDir.setBorder(null);
btnCancel.setText("Close");
//resize();
frame.setVisible(true);
}
示例7: mouseMove
import java.awt.MouseInfo; //导入方法依赖的package包/类
/**
* 处理鼠标移动
*/
public void mouseMove(String info) {
String args[] = info.split(",");
String x = args[0];
String y = args[1];
float px = Float.valueOf(x);
float py = Float.valueOf(y);
PointerInfo pinfo = MouseInfo.getPointerInfo(); // 得到鼠标的坐标
java.awt.Point p = pinfo.getLocation();
double mx = p.getX(); // 得到当前电脑鼠标的坐标
double my = p.getY();
try {
java.awt.Robot robot = new Robot();
robot.mouseMove((int) (mx + px), (int) (my + py));
} catch (AWTException e) {
}
}
示例8: run
import java.awt.MouseInfo; //导入方法依赖的package包/类
@Override
public void run() {
terminate = false;
PointerInfo pointerInfo = MouseInfo.getPointerInfo();
Point pointerLocation = pointerInfo.getLocation();
mouseX = pointerLocation.getX();
mouseY = pointerLocation.getY();
while (!terminate) {
try {
mouseX += (x * Math.abs(x) * 100);
mouseY += (y * Math.abs(y) * 100);
robot.mouseMove(new Double(mouseX).intValue(), new Double(mouseY).intValue());
Thread.sleep(10);
} catch (Exception e) {
// TODO: handle exception
}
}
mouseX = null;
mouseY = null;
}
示例9: focusGained
import java.awt.MouseInfo; //导入方法依赖的package包/类
@Override
public void focusGained(FocusEvent e) {
this.stateTransitionTracker.turnOffModelChangeTracking();
try {
super.focusGained(e);
if (!this.button.isShowing()) {
// shouldn't happen. Is some lurking Swing bug
return;
}
try {
PointerInfo pi = MouseInfo.getPointerInfo();
int px = pi.getLocation().x
- this.button.getLocationOnScreen().x;
int py = pi.getLocation().y
- this.button.getLocationOnScreen().y;
this.button.getModel()
.setRollover(this.button.contains(px, py));
} catch (AccessControlException ace) {
// sandbox - give up
}
} finally {
this.stateTransitionTracker.onModelStateChanged();
}
}
示例10: getCurrentCursorLocation
import java.awt.MouseInfo; //导入方法依赖的package包/类
private Point getCurrentCursorLocation() {
Point res = null;
PointerInfo pi = MouseInfo.getPointerInfo();
if( null != pi ) {
res = pi.getLocation();
}
return res;
}
示例11: getScreenBounds
import java.awt.MouseInfo; //导入方法依赖的package包/类
private Rectangle getScreenBounds() {
Rectangle res = null;
PointerInfo pi = MouseInfo.getPointerInfo();
if( null != pi ) {
GraphicsDevice gd = pi.getDevice();
if( gd != null ) {
GraphicsConfiguration gc = gd.getDefaultConfiguration();
if( gc != null ) {
res = gc.getBounds();
}
}
}
return res;
}
示例12: ensureSelected
import java.awt.MouseInfo; //导入方法依赖的package包/类
/** Workaround for JDK bug 6663119, it ensures that first item in submenu
* is correctly selected during keyboard navigation.
*/
private void ensureSelected () {
if (menu.getMenuComponentCount() <=0) {
return;
}
Component first = menu.getMenuComponent(0);
if (!(first instanceof JMenuItem)) {
return;
}
PointerInfo pointerInfo = MouseInfo.getPointerInfo();
if (pointerInfo == null) {
return; // probably a mouseless computer
}
Point loc = pointerInfo.getLocation();
SwingUtilities.convertPointFromScreen(loc, menu);
MenuElement[] selPath =
MenuSelectionManager.defaultManager().getSelectedPath();
// apply workaround only when mouse is not hovering over menu
// (which signalizes mouse driven menu traversing) and only
// when selected menu path contains expected value - submenu itself
if (!menu.contains(loc) && selPath.length > 0 &&
menu.getPopupMenu() == selPath[selPath.length - 1]) {
// select first item in submenu through MenuSelectionManager
MenuElement[] newPath = new MenuElement[selPath.length + 1];
System.arraycopy(selPath, 0, newPath, 0, selPath.length);
JMenuItem firstItem = (JMenuItem)first;
newPath[selPath.length] = firstItem;
MenuSelectionManager.defaultManager().setSelectedPath(newPath);
}
}
示例13: update
import java.awt.MouseInfo; //导入方法依赖的package包/类
@Override
public void update() throws Exception
{
PointerInfo pi = MouseInfo.getPointerInfo();
Point epoint = pi == null ? lastCursorPoint : pi.getLocation();
if (!epoint.equals(lastCursorPoint))
{
lastCursorPoint = epoint;
MainDialog.resetActivityTimer(MOUSE_POINTER);
}
}
示例14: doSetFocus
import java.awt.MouseInfo; //导入方法依赖的package包/类
@Override
protected void doSetFocus() {
text.setFocus();
text.setSelection(text.getText().length());
if (cmode.isDirectlyConnected() && Activator.getStore().getBoolean(DevicePreferenceConstants.SHOW_CONTROL_TOOLTIPS)) {
PointerInfo a = MouseInfo.getPointerInfo();
java.awt.Point loc = a.getLocation();
tip.setLocation(loc.x, loc.y+20);
tip.setVisible(true);
}
}
示例15: showTip
import java.awt.MouseInfo; //导入方法依赖的package包/类
/**
* Show the top where the mouse is.
* @param tip
* @param message
*/
public static void showTip(ToolTip tip, String message) {
if (tip==null) return;
tip.setMessage(message);
PointerInfo a = MouseInfo.getPointerInfo();
java.awt.Point loc = a.getLocation();
tip.setLocation(loc.x, loc.y+20);
tip.setVisible(true);
}