I am working on a geometry program where I need to draw 'infinite' lines. My class Line has a method
public void draw(Graphics2D g){
//... calculate x1,y1,x2,y2 here ...
g.draw(new Line2D.Double(x1,y1, x2,y2));
}
My idea is to choose the coordinates large enough so they will be off the visible surface. But I don't know, and this is my question, how do I know the coordinates of the corners of the visible surface? Graphic's method getClip() sounded nice, but apparently it only returns a custom clip the user set before. Apparently what I need is called 'device clip' in the docs.
And before you suggest a big length, like 10000, I don't mean pixel size here. I use transforms for zooming and translating and such, so 10000 might well be visible.
edit: I just wanted to tell you what I ended up doing: I defined a reasonably large constants for maximum screen width and height (they might need adjusting in 10 years), then I apply the inverse of my current display transformation to this 'screen' to know the necessary length of my 'infinite' lines. I.e. the problem is not solved, only confined to a single spot in the code.
Change window Size of a JFrame To resize a frame, There is a method JFrame. setSize(int width, int height) which takes two parameters width and height.
Is
Rectangle bounds = g.getDeviceConfiguration().getBounds()
what you're after perhaps? I don't know myself, but just browsing the docs it looks like a reasonable bet...
How about
java.awt.Toolkit.getDefaultToolkit().getScreenSize()
which returns a Dimension object with the size of the screen.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With