What package is the window.getSize() ?
hi guys, am stil new to java their was a snippest code about getting screen size i've being seeing onine calling window.getSize() in what package is the object located.
// Get the size of the screen
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
// Determine the new location of the window
int w = window.getSize().width; //what package is window.getSize() from?
int h = window.getSize().height; //what package is window.getSize() from?
int x = (dim.width-w)/2;
int y = (dim.height-h)/2;
// Move the window
window.setLocation(x, y);
it will be helpful if someone can say something
57 Minutes
Discussion Span
Related Article: Constructors for window
is a solved Java discussion thread by ambageo that has 5 replies, was last updated 4 months ago and has been tagged with the keywords: window, frame, constructor.
hakeemtunde
Junior Poster in Training
50 posts since Dec 2007
Reputation Points: 10
Solved Threads: 8
Skill Endorsements: 2
window is a variable. From the context I guess its a top-level Swing component (JFrame, JDialog, JApplet...)
getSize() is a method that's available for all Swing components. Top-level components inherit it from java.awt.Component. Others inherit it from javax.swing.JComponent.
ps *window.setLocationRelativeTo(null); * does the same thing as that code, but in one line, and it handles multi-screen configurations sensibly.
JamesCherrill
... trying to help
8,519 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30
Ok. If am to write that code how do i go about it. I mean can you write the code for me so as for me to know is propery instantiated and used in context of the above code
hakeemtunde
Junior Poster in Training
50 posts since Dec 2007
Reputation Points: 10
Solved Threads: 8
Skill Endorsements: 2
It assumes yo have a JFrame or whatever called window. Then when you run the code it moves your window to the centre of the screen. That's all. If your window is called something else, use that name instead of window. You just put the code somewhere in one of your methods, whenever you want the screen to be centered.
JamesCherrill
... trying to help
8,519 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30
hakeemtunde
Junior Poster in Training
50 posts since Dec 2007
Reputation Points: 10
Solved Threads: 8
Skill Endorsements: 2
Question Answered as of 7 Months Ago by
JamesCherrill