本文整理汇总了Java中java.awt.Window.setLocationRelativeTo方法的典型用法代码示例。如果您正苦于以下问题:Java Window.setLocationRelativeTo方法的具体用法?Java Window.setLocationRelativeTo怎么用?Java Window.setLocationRelativeTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Window
的用法示例。
在下文中一共展示了Window.setLocationRelativeTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.awt.Window; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
final Window window = new BackgroundIsNotUpdated(null);
window.setSize(300, 300);
window.setLocationRelativeTo(null);
window.setVisible(true);
sleep();
window.setBackground(Color.GREEN);
sleep();
final Robot robot = new Robot();
robot.setAutoDelay(200);
Point point = window.getLocationOnScreen();
Color color = robot.getPixelColor(point.x + window.getWidth() / 2,
point.y + window.getHeight() / 2);
window.dispose();
if (!color.equals(Color.GREEN)) {
throw new RuntimeException(
"Expected: " + Color.GREEN + " , Actual: " + color);
}
}
示例2: main
import java.awt.Window; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
final boolean dump = Boolean.parseBoolean(args[0]);
final Window w = new Frame() {
@Override
public void list(final PrintStream out, final int indent) {
super.list(out, indent);
dumped = true;
}
};
w.setSize(200, 200);
w.setLocationRelativeTo(null);
w.setVisible(true);
final Robot robot = new Robot();
robot.setAutoDelay(50);
robot.setAutoWaitForIdle(true);
robot.mouseMove(w.getX() + w.getWidth() / 2,
w.getY() + w.getHeight() / 2);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_F1);
robot.keyRelease(KeyEvent.VK_F1);
robot.keyRelease(KeyEvent.VK_SHIFT);
robot.keyRelease(KeyEvent.VK_CONTROL);
w.dispose();
if (dumped != dump) {
throw new RuntimeException("Exp:" + dump + ", actual:" + dumped);
}
}
示例3: repackWindow
import java.awt.Window; //导入方法依赖的package包/类
/**
* Repacks the window
*/
private void repackWindow() {
Window window = SwingUtilities.getWindowAncestor(this);
if (window != null) {
window.pack();
window.setLocationRelativeTo(null);
}
}
示例4: centreOnScreen
import java.awt.Window; //导入方法依赖的package包/类
public static void centreOnScreen(Window window)
{
Window owner = window.getOwner();
// If the window has an owner, use the same graphics configuration so it
// will
// open on the same screen. Otherwise, grab the mouse pointer and work
// from there.
GraphicsConfiguration gc = owner != null ? owner.getGraphicsConfiguration() : MouseInfo.getPointerInfo()
.getDevice().getDefaultConfiguration();
if( gc != null )
{
window.setBounds(centre(getUsableScreenBounds(gc), window.getBounds()));
}
else
{
// Fall-back to letting Java do the work
window.setLocationRelativeTo(null);
}
}
示例5: main
import java.awt.Window; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
final Window window = new BackgroundIsNotUpdated(null);
window.setSize(300, 300);
window.setLocationRelativeTo(null);
window.setVisible(true);
window.requestFocus();
final ExtendedRobot robot = new ExtendedRobot();
robot.setAutoDelay(200);
robot.waitForIdle(1000);
window.setBackground(Color.GREEN);
robot.waitForIdle(1000);
Point point = window.getLocationOnScreen();
Color color = robot.getPixelColor(point.x + window.getWidth() / 2,
point.y + window.getHeight() / 2);
window.dispose();
if (!color.equals(Color.GREEN)) {
throw new RuntimeException(
"Expected: " + Color.GREEN + " , Actual: " + color);
}
}
示例6: packAndCenter
import java.awt.Window; //导入方法依赖的package包/类
public static void packAndCenter(final Window win) {
// pack
win.pack();
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
win.setSize(Math.min(win.getWidth(), screenSize.width), Math.min(win.getHeight(), screenSize.height - 20));
// Center on screen
win.setLocationRelativeTo(null);
}