本文整理匯總了Java中java.awt.Frame.getLocationOnScreen方法的典型用法代碼示例。如果您正苦於以下問題:Java Frame.getLocationOnScreen方法的具體用法?Java Frame.getLocationOnScreen怎麽用?Java Frame.getLocationOnScreen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Frame
的用法示例。
在下文中一共展示了Frame.getLocationOnScreen方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startRegTest
import java.awt.Frame; //導入方法依賴的package包/類
private static Thread startRegTest(final Frame f) {
Thread robot = new Thread(new Runnable() {
public void run() {
Robot r = Util.createRobot();
dragWindow(f, 100, 100, r);
// wait for the location to be set.
sleepFor(2000);
final Point l2 = f.getLocationOnScreen();
// double click should maximize the frame
doubleClick(r);
// wait for location again.
sleepFor(2000);
final Point l3 = f.getLocationOnScreen();
if (l3.equals(l2)) {
throw new RuntimeException("Bad location after maximize. Window location has not moved");
}
}
});
return robot;
}
示例2: robotKeyPressTest
import java.awt.Frame; //導入方法依賴的package包/類
public void robotKeyPressTest() throws Exception {
SwingUtilities.invokeAndWait(() -> {
frame = new Frame();
frame.setSize(300, 300);
frame.setVisible(true);
});
Robot robot = new Robot();
robot.waitForIdle();
Point pt = frame.getLocationOnScreen();
robot.mouseMove(((int) pt.getX() + frame.getWidth()) / 2,
((int) pt.getY() + frame.getHeight()) / 2);
robot.waitForIdle();
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.waitForIdle();
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.waitForIdle();
robot.keyPress(KeyEvent.VK_ENTER);
robot.waitForIdle();
robot.keyRelease(KeyEvent.VK_ENTER);
robot.waitForIdle();
SwingUtilities.invokeAndWait(() -> {
frame.dispose();
});
}
示例3: run
import java.awt.Frame; //導入方法依賴的package包/類
public void run() {
frame = new Frame();
final DragSourceListener dragSourceListener = new DragSourceAdapter() {
public void dragDropEnd(DragSourceDropEvent e) {
dropSuccess = e.getDropSuccess();
System.err.println("Drop was successful: " + dropSuccess);
}
};
DragGestureListener dragGestureListener = new DragGestureListener() {
public void dragGestureRecognized(DragGestureEvent dge) {
dge.startDrag(null, new StringSelection("OK"), dragSourceListener);
}
};
new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_MOVE,
dragGestureListener);
DropTargetAdapter dropTargetListener = new DropTargetAdapter() {
public void drop(DropTargetDropEvent dtde) {
dtde.acceptDrop(DnDConstants.ACTION_MOVE);
dtde.dropComplete(true);
System.err.println("Drop");
}
};
new DropTarget(frame, dropTargetListener);
//What would normally go into main() will probably go here.
//Use System.out.println for diagnostic messages that you want
//to read after the test is done.
frame.setUndecorated(true);
frame.setBounds(100, 100, 200, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
Robot robot = Util.createRobot();
Util.waitForIdle(robot);
Point startPoint = frame.getLocationOnScreen();
Point endPoint = new Point(startPoint);
startPoint.translate(50, 50);
endPoint.translate(150, 150);
Util.drag(robot, startPoint, endPoint, InputEvent.BUTTON2_MASK);
Util.waitForIdle(robot);
robot.delay(500);
if (dropSuccess) {
System.err.println("test passed");
} else {
throw new RuntimeException("test failed: drop was not successful");
}
}