當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。