本文整理匯總了Java中java.awt.Window.getLocationOnScreen方法的典型用法代碼示例。如果您正苦於以下問題:Java Window.getLocationOnScreen方法的具體用法?Java Window.getLocationOnScreen怎麽用?Java Window.getLocationOnScreen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Window
的用法示例。
在下文中一共展示了Window.getLocationOnScreen方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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 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);
}
}
示例3: calculatePosition
import java.awt.Window; //導入方法依賴的package包/類
private Point calculatePosition(Component source) {
int xSource = source.getLocationOnScreen().x;
int ySource = source.getLocationOnScreen().y;
// get size of popup
Dimension popupSize = ((Component) popupComponent).getSize();
if (popupSize.width == 0) {
popupSize = ((Component) popupComponent).getPreferredSize();
}
int xPopup = 0;
int yPopup = 0;
// get max x and y window positions
Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
int maxX = focusedWindow.getLocationOnScreen().x + focusedWindow.getWidth();
int maxY = focusedWindow.getLocationOnScreen().y + focusedWindow.getHeight();
switch (position) {
case VERTICAL:
// place popup at sources' x position
xPopup = xSource;
// check if popup is outside active window
if (xPopup + popupSize.width > maxX) {
// move popup x position to the left
// to fit inside the active window
xPopup = maxX - popupSize.width - BORDER_OFFSET;
}
// place popup always below source (to avoid overlapping)
yPopup = ySource + source.getHeight();
// if the popup now would be moved outside of RM Studio to the left it would look
// silly, so in that case just show it at its intended position and let it be cut
// off on the right side as we cannot do anything about it
if (xPopup < focusedWindow.getLocationOnScreen().x
|| (xPopup - focusedWindow.getLocationOnScreen().x) + popupSize.width > focusedWindow.getWidth()) {
xPopup = xSource;
}
break;
case HORIZONTAL:
// place popup always to the right side of the source (to avoid overlapping)
xPopup = xSource + source.getWidth();
yPopup = ySource;
// check if popup is outside active window
if (yPopup + popupSize.height > maxY) {
// move popup upwards to fit into active window
yPopup = maxY - popupSize.height - BORDER_OFFSET;
}
// if the popup now would be moved outside of RM Studio at the top it would look
// silly, so in that case just show it at its intended position and let it be cut
// off on the bottom side as we cannot do anything about it
if (yPopup < focusedWindow.getLocationOnScreen().y
|| (yPopup - focusedWindow.getLocationOnScreen().y) + popupSize.height > focusedWindow.getHeight()) {
yPopup = ySource;
}
break;
}
return new Point(xPopup, yPopup);
}
示例4: 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);
}
示例5: displayStatusDialog
import java.awt.Window; //導入方法依賴的package包/類
/**
* displays a dialog box describing the status of an event
*/
void displayStatusDialog(Window w, String status) {
ToolDialog sd = new ToolDialog
(PolicyTool.getMessage("Status"), tool, this, true);
// find the location of the PolicyTool gui
Point location = ((w == null) ?
getLocationOnScreen() : w.getLocationOnScreen());
//sd.setBounds(location.x + 50, location.y + 50, 500, 100);
sd.setLayout(new GridBagLayout());
JLabel label = new JLabel(status);
addNewComponent(sd, label, 0,
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
JButton okButton = new JButton(PolicyTool.getMessage("OK"));
ActionListener okListener = new StatusOKButtonListener(sd);
okButton.addActionListener(okListener);
addNewComponent(sd, okButton, 1,
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
sd.getRootPane().setDefaultButton(okButton);
sd.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
sd.pack();
sd.setLocationRelativeTo(w);
sd.setVisible(true);
}
示例6: displayWarningLog
import java.awt.Window; //導入方法依賴的package包/類
/**
* display the warning log
*/
void displayWarningLog(Window w) {
ToolDialog wd = new ToolDialog
(PolicyTool.getMessage("Warning"), tool, this, true);
// find the location of the PolicyTool gui
Point location = ((w == null) ?
getLocationOnScreen() : w.getLocationOnScreen());
//wd.setBounds(location.x + 50, location.y + 50, 500, 100);
wd.setLayout(new GridBagLayout());
JTextArea ta = new JTextArea();
ta.setEditable(false);
for (int i = 0; i < tool.warnings.size(); i++) {
ta.append(tool.warnings.elementAt(i));
ta.append(PolicyTool.getMessage("NEWLINE"));
}
addNewComponent(wd, ta, 0,
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
BOTTOM_PADDING);
ta.setFocusable(false);
JButton okButton = new JButton(PolicyTool.getMessage("OK"));
ActionListener okListener = new CancelButtonListener(wd);
okButton.addActionListener(okListener);
addNewComponent(wd, okButton, 1,
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
LR_PADDING);
wd.getRootPane().setDefaultButton(okButton);
wd.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
wd.pack();
wd.setLocationRelativeTo(w);
wd.setVisible(true);
}
示例7: displayErrorDialog
import java.awt.Window; //導入方法依賴的package包/類
/**
* displays a dialog box describing an error which occurred.
*/
void displayErrorDialog(Window w, String error) {
ToolDialog ed = new ToolDialog
(PolicyTool.getMessage("Error"), tool, this, true);
// find where the PolicyTool gui is
Point location = ((w == null) ?
getLocationOnScreen() : w.getLocationOnScreen());
//ed.setBounds(location.x + 50, location.y + 50, 600, 100);
ed.setLayout(new GridBagLayout());
JLabel label = new JLabel(error);
addNewComponent(ed, label, 0,
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
JButton okButton = new JButton(PolicyTool.getMessage("OK"));
ActionListener okListener = new ErrorOKButtonListener(ed);
okButton.addActionListener(okListener);
addNewComponent(ed, okButton, 1,
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
ed.getRootPane().setDefaultButton(okButton);
ed.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
ed.pack();
ed.setLocationRelativeTo(w);
ed.setVisible(true);
}
示例8: getCenterPoint
import java.awt.Window; //導入方法依賴的package包/類
private static Point getCenterPoint(Window window) {
Point centerPoint = window.getLocationOnScreen();
centerPoint.translate(window.getWidth() / 2, window.getHeight() / 2);
return centerPoint;
}
示例9: getTitlePoint
import java.awt.Window; //導入方法依賴的package包/類
public static Point getTitlePoint(Window decoratedWindow) {
Point p = decoratedWindow.getLocationOnScreen();
Dimension d = decoratedWindow.getSize();
return new Point(p.x + (int)(d.getWidth()/2),
p.y + (int)(decoratedWindow.getInsets().top/2));
}