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


Java Component.getLocationOnScreen方法代码示例

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


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

示例1: click

import java.awt.Component; //导入方法依赖的package包/类
@Override public void click(Component component, Buttons button, int clickCount, int xoffset, int yoffset) {
    ensureVisible(component, new Rectangle(xoffset, yoffset, 50, 50));
    int b = InputEvent.BUTTON1_MASK;
    if (button.getButton() == 0) {
        b = InputEvent.BUTTON1_MASK;
    } else if (button.getButton() == 1) {
        b = InputEvent.BUTTON2_MASK;
    } else if (button.getButton() == 2) {
        b = InputEvent.BUTTON3_MASK;
    }
    Point compLocation = component.getLocationOnScreen();
    int x = compLocation.x + xoffset;
    int y = compLocation.y + yoffset;
    robotXmouseMove(x, y);
    for (int i = 0; i < clickCount; i++) {
        robotXmousePress(b);
        robotXmouseRelease(b);
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:20,代码来源:RobotDevice.java

示例2: calculatePosition

import java.awt.Component; //导入方法依赖的package包/类
private Point calculatePosition(Component source) {
	int xSource = source.getLocationOnScreen().x;
	int ySource = source.getLocationOnScreen().y;

	// get size of popup
	Dimension popupSize = ((Component) popupComponent).getSize();
	if (popupSize.width == 0) {
		popupSize = ((Component) popupComponent).getPreferredSize();
	}

	int xPopup = 0;
	int yPopup = 0;

	// get max x and y window positions
	Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
	int maxX = focusedWindow.getLocationOnScreen().x + focusedWindow.getWidth();
	int maxY = focusedWindow.getLocationOnScreen().y + focusedWindow.getHeight();

	switch (position) {
		case VERTICAL:

			// place popup at sources' x position
			xPopup = xSource;

			// check if popup is outside active window
			if (xPopup + popupSize.width > maxX) {

				// move popup x position to the left
				// to fit inside the active window
				xPopup = maxX - popupSize.width - BORDER_OFFSET;
			}

			// place popup always below source (to avoid overlapping)
			yPopup = ySource + source.getHeight();

			// if the popup now would be moved outside of RM Studio to the left it would look
			// silly, so in that case just show it at its intended position and let it be cut
			// off on the right side as we cannot do anything about it
			if (xPopup < focusedWindow.getLocationOnScreen().x
					|| (xPopup - focusedWindow.getLocationOnScreen().x) + popupSize.width > focusedWindow.getWidth()) {
				xPopup = xSource;
			}

			break;
		case HORIZONTAL:

			// place popup always to the right side of the source (to avoid overlapping)
			xPopup = xSource + source.getWidth();

			yPopup = ySource;

			// check if popup is outside active window
			if (yPopup + popupSize.height > maxY) {

				// move popup upwards to fit into active window
				yPopup = maxY - popupSize.height - BORDER_OFFSET;
			}

			// if the popup now would be moved outside of RM Studio at the top it would look
			// silly, so in that case just show it at its intended position and let it be cut
			// off on the bottom side as we cannot do anything about it
			if (yPopup < focusedWindow.getLocationOnScreen().y
					|| (yPopup - focusedWindow.getLocationOnScreen().y) + popupSize.height > focusedWindow.getHeight()) {
				yPopup = ySource;
			}

			break;
	}

	return new Point(xPopup, yPopup);

}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:73,代码来源:PopupAction.java

示例3: ComponentNode

import java.awt.Component; //导入方法依赖的package包/类
public ComponentNode(Component comp) {
    super(comp.getClass());
    try {
        props = Operator.createOperator(comp).getDump();
    } catch (Exception e) {
        props = new Hashtable<>();
    }
    clss = comp.getClass().getName();
    compToString = comp.toString();
    this.comp = comp;
    x = comp.getLocationOnScreen().x;
    y = comp.getLocationOnScreen().y;
    w = comp.getWidth();
    h = comp.getHeight();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:GUIBrowser.java

示例4: computeActiveArea

import java.awt.Component; //导入方法依赖的package包/类
/** @return Area in which automatic slide in is preserved. Can return
 * null signalizing that components making active area bounds are not yet 
 * ready or showing.
 */
private Rectangle computeActiveArea() {
    Component slidedComp = slideBar.getSlidedComp();
    if (slidedComp == null || !slidedComp.isShowing()) {
        return null;
    }
    
    Point slideBarLoc = slideBar.getLocationOnScreen();
    Rectangle actArea = new Rectangle(slideBarLoc.x - 1, slideBarLoc.y - 1,
                            slideBar.getWidth() - 1, slideBar.getHeight() - 1);
    
    Point slidedCompLoc = slidedComp.getLocationOnScreen();
    
    int slidex = slidedCompLoc.x;
    int slidey = slidedCompLoc.y;
    int slideh = slidedComp.getHeight();
    int slidew = slidedComp.getWidth();
    int orientation = slideBar.getModel().getOrientation();
    if (orientation == SlideBarDataModel.WEST) {
        slidew = slidew + ResizeGestureRecognizer.RESIZE_BUFFER;
    }
    if (orientation == SlideBarDataModel.EAST) {
        slidew = slidew + ResizeGestureRecognizer.RESIZE_BUFFER;
        slidex = slidex - ResizeGestureRecognizer.RESIZE_BUFFER;
    }
    if (orientation == SlideBarDataModel.SOUTH) {
        slideh = slideh + ResizeGestureRecognizer.RESIZE_BUFFER;
        slidey = slidey - ResizeGestureRecognizer.RESIZE_BUFFER;
    }
    if (orientation == SlideBarDataModel.NORTH) {
        slideh = slideh + ResizeGestureRecognizer.RESIZE_BUFFER;
    }
    actArea = SwingUtilities.computeUnion(
        slidex, slidey, slidew,
        slideh, actArea);
    
    return actArea;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:SlideGestureRecognizer.java

示例5: mouseClickOnComp

import java.awt.Component; //导入方法依赖的package包/类
static void mouseClickOnComp(Robot r, Component comp) {
    Point loc = comp.getLocationOnScreen();
    loc.x += comp.getWidth() / 2;
    loc.y += comp.getHeight() / 2;
    r.mouseMove(loc.x, loc.y);
    r.delay(10);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.delay(10);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:EndlessLoopTest.java

示例6: moveMouseTo

import java.awt.Component; //导入方法依赖的package包/类
/**
 * Move mouse cursor to the center of the Component.
 * @param c Component the mouse is placed over
 */
public void moveMouseTo(Component c) {
    Point p = c.getLocationOnScreen();
    Dimension size = c.getSize();
    p.x += size.width / 2;
    p.y += size.height / 2;
    mouseMove(p.x, p.y);
    delay();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:JRobot.java

示例7: showDialog

import java.awt.Component; //导入方法依赖的package包/类
public static int showDialog(Component comp, String text) {
    ReplaceOptionsDialog dlg = new ReplaceOptionsDialog(text);
    Dimension dlgSize = new Dimension(300, 150);
    dlg.setSize(300, 150);
    Dimension frmSize = comp.getSize();
    Point loc = comp.getLocationOnScreen();
    dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
    dlg.setModal(true);
    dlg.setVisible(true);
    return dlg.option;
}
 
开发者ID:ser316asu,项目名称:SER316-Dresden,代码行数:12,代码来源:ReplaceOptionsDialog.java

示例8: waitTillShownEx

import java.awt.Component; //导入方法依赖的package包/类
public static void waitTillShownEx(final Component comp) throws InterruptedException {
    while (true) {
        try {
            Thread.sleep(100);
            comp.getLocationOnScreen();
            break;
        } catch (IllegalComponentStateException e) {}
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:Util.java

示例9: moveMouseTo

import java.awt.Component; //导入方法依赖的package包/类
private void moveMouseTo(ExtendedRobot robot, Component c) {
    java.awt.Point p = c.getLocationOnScreen();
    java.awt.Dimension size = c.getSize();
    p.x += size.width / 2;
    p.y += size.height / 2;
    robot.mouseMove(p.x, p.y);
    robot.delay(100);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:bug6415145.java

示例10: show

import java.awt.Component; //导入方法依赖的package包/类
@Override
public void show(Event e) {
    Component origin = (Component)e.target;
    if (origin != null) {
        Point loc = origin.getLocationOnScreen();
        e.x += loc.x;
        e.y += loc.y;
        execute(ptr -> nativeShowPopupMenu(ptr, e.x, e.y));
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:CPopupMenu.java

示例11: doCapture

import java.awt.Component; //导入方法依赖的package包/类
private static void doCapture(Component test) {
    try {
        Thread.sleep(2000);
    } catch (InterruptedException ex) {}
    // Grab the screen region
    try {
        Robot robot = new Robot();
        Point pt1 = test.getLocationOnScreen();
        Rectangle rect =
            new Rectangle(pt1.x, pt1.y, test.getWidth(), test.getHeight());
        capture = robot.createScreenCapture(rect);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:DrawImageBilinear.java

示例12: main

import java.awt.Component; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
    ExtendedRobot robot = new ExtendedRobot();
    robot.setAutoDelay(50);
    final Frame frame = new Frame();
    final Component label = new PaintNativeOnUpdate();
    frame.setBackground(Color.RED);
    frame.add(label);
    frame.setSize(300, 300);
    frame.setUndecorated(true);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    robot.waitForIdle(1000);
    label.repaint();// first paint
    robot.waitForIdle(1000);
    label.repaint();// incremental paint
    robot.waitForIdle(1000);

    Point point = label.getLocationOnScreen();
    Color color = robot.getPixelColor(point.x + label.getWidth() / 2,
                                      point.y + label.getHeight() / 2);
    if (!color.equals(Color.GREEN)) {
        System.err.println("Expected color = " + Color.GREEN);
        System.err.println("Actual color = " + color);
        throw new RuntimeException();
    }
    frame.dispose();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:PaintNativeOnUpdate.java

示例13: pointOnComp

import java.awt.Component; //导入方法依赖的package包/类
/**
 * Moves mouse pointer in the center of given {@code comp} component
 * using {@code robot} parameter.
 */
public static void pointOnComp(final Component comp, final Robot robot) {
    Rectangle bounds = new Rectangle(comp.getLocationOnScreen(), comp.getSize());
    robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:Util.java

示例14: convertCoords

import java.awt.Component; //导入方法依赖的package包/类
/** Converts relative coordinates inside one of the components
 * laying on the designer to coordinates relative to handleLayer()
 * @see #handleLayer()
 * @see #componentLayer()
 * @see #findComponent(org.netbeans.jemmy.ComponentChooser, int)
 * @see #findComponent(org.netbeans.jemmy.ComponentChooser)
 * @see #findComponent(java.lang.Class, int)
 * @see #findComponent(java.lang.Class)
 * @param subComponent Component in designer.
 * @param localCoords Local <code>subComponent</code>'s coordinates
 * @return coordinates relative to handle layer
 */
public Point convertCoords(Component subComponent, Point localCoords) {
    Point subLocation = subComponent.getLocationOnScreen();
    Point location = handleLayer().getLocationOnScreen();
    return (new Point(subLocation.x - location.x + localCoords.x,
            subLocation.y - location.y + localCoords.y));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:FormDesignerOperator.java

示例15: setLocationByComponent

import java.awt.Component; //导入方法依赖的package包/类
/**
 * Altera as variáveis Point de evento para exibir a linha de origem e
 * destino do evento gerado pelo oponente
 *
 * @param point variável a ser modificada
 * @param c componente de origem ou destino
 */
private void setLocationByComponent(Point point, Component c) {
    Point p = c.getLocationOnScreen();
    point.x = p.x + c.getWidth() / 2;
    point.y = p.y + c.getHeight() / 2;
}
 
开发者ID:limagiran,项目名称:hearthstone,代码行数:13,代码来源:PartidaView.java


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