-2
beetwen getLocation()
和getLocationOnScreen()
方法有什麼不同JFrame
?Java:在JFrame上,beetwen getLocation()和getLocationOnScreen()有什麼區別?
我想測試這段代碼有什麼區別,但結果是一樣的。我應該使用哪種方法?
public static void main(String args[]) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(150, 100);
frame.setVisible(true);
System.out.println("getLocation: " + frame.getLocation().getX() + " " + frame.getLocation().getY());
System.out.println("getLocationOnScreen: " + frame.getLocationOnScreen().getX() + " " + frame.getLocationOnScreen().getY());
}
輸出:
getLocation: 150.0 100.0
getLocationOnScreen: 150.0 100.0
這些是Component的方法,因此不特定於JFrame。他們的javadoc解釋他們做什麼。閱讀javadoc:這是你的朋友。 –