本文整理汇总了Java中java.awt.Window.getLocation方法的典型用法代码示例。如果您正苦于以下问题:Java Window.getLocation方法的具体用法?Java Window.getLocation怎么用?Java Window.getLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Window
的用法示例。
在下文中一共展示了Window.getLocation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveWindowLocation
import java.awt.Window; //导入方法依赖的package包/类
/**
* This static method can be used to save the window x,y, position (but not
* size). This statis method saves the window origin but not the size, based
* on a classname-based key in the supplied preferences node.
*
* @param window the window to save for
* @param prefs user preferences node
* @see #restoreWindowLocation
*/
public static void saveWindowLocation(Window window, Preferences prefs) {
String name = window.getClass().getName();
Point p = new Point(0, 0);
try {
p = window.getLocationOnScreen();
} catch (IllegalComponentStateException e) {
p = window.getLocation();
}
prefs.putInt(name + ".XPosition", (int) p.getX());
prefs.putInt(name + ".YPosition", (int) p.getY());
// log.info("saved location for window "+name);
}