本文整理匯總了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
}
示例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);
}
示例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;
}