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


Java JButton.getLocationOnScreen方法代码示例

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


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

示例1: prepareControls

import javax.swing.JButton; //导入方法依赖的package包/类
/**
 * Creating two JInternalFrames in JDesktopPanes. Put lightweight component into one frame and heavyweight into another.
 */
@Override
protected void prepareControls() {
    JDesktopPane desktopPane = new JDesktopPane();

    JFrame frame = new JFrame("Test Window");
    frame.setSize(300, 300);
    frame.setContentPane(desktopPane);
    frame.setVisible(true);
    JInternalFrame bottomFrame = new JInternalFrame("bottom frame", false, false, false, false);
    bottomFrame.setSize(220, 220);
    desktopPane.add(bottomFrame);
    bottomFrame.setVisible(true);

    super.propagateAWTControls(bottomFrame);
    JInternalFrame topFrame = new JInternalFrame("top frame", false, false, false, false);
    topFrame.setSize(200, 200);
    JButton jbutton = new JButton("LW Button") {{
            addMouseListener(new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent e) {
                    lwClicked = true;
                }
            });
        }};
    topFrame.add(jbutton);
    desktopPane.add(topFrame);
    topFrame.setVisible(true);
    lLoc = jbutton.getLocationOnScreen();
    lLoc.translate(jbutton.getWidth()/2, jbutton.getWidth()/2); //click at middle of the button
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:JInternalFrameOverlapping.java

示例2: clickOn

import javax.swing.JButton; //导入方法依赖的package包/类
private void clickOn(JButton button) {
    waitForIdle();
    waitForIdle();
    waitForIdle();
    waitForIdle();
    waitForIdle();
    waitForIdle();
    Point p = button.getLocationOnScreen();
    Dimension d = button.getSize();
    robot.mouseMove(p.x + d.width / 2, p.y + d.height / 2);
    robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:EditPadTest.java

示例3: pressOK

import javax.swing.JButton; //导入方法依赖的package包/类
private static boolean pressOK(Component comp) {

        JInternalFrame internalFrame
                = findModalInternalFrame(comp, QUESTION);

        if (internalFrame == null) {
            return false;
        }

        JButton button = (JButton) findButton(internalFrame);

        if (button == null) {
            return false;
        }

        try {
            Robot robot = new Robot();
            Point location = button.getLocationOnScreen();
            Rectangle bounds = button.getBounds();
            int centerX = (int) (location.getX() + bounds.getWidth() / 2);
            int centerY = (int) (location.getY() + bounds.getHeight() / 2);
            robot.mouseMove(centerX, centerY);
            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
        } catch (IllegalComponentStateException ignore) {
            return false;
        } catch (AWTException e) {
            throw new RuntimeException(e);
        }
        return true;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:bug6219960.java


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