This site requires JavaScript, please enable it in your browser!
Greenfoot back
K_O_P
K_O_P wrote ...

2012/4/5

How to get the hight and width of the computer screen?

K_O_P K_O_P

2012/4/5

#
Hey guys! I've got a difficult question... How can you get the height and width of the computer screen?
tkiesel tkiesel

2012/4/5

#
Maybe? Toolkit.getDefaultTolkit().getScreenSize().getWidth() and Toolkit.getDefaultTolkit().getScreenSize().getHeight() Those will be doubles though, so you may need to cast them to int, depending on your use. (int)Toolkit.getDefaultTolkit().getScreenSize().getWidth() (int)Toolkit.getDefaultTolkit().getScreenSize().getHeight() I'm basing this off of the info at http://www.javacoffeebreak.com/faq/faq0015.html and the Java API for the Dimension class.
K_O_P K_O_P

2012/4/5

#
Thank you! But I more meant, how to get the size, noting the taskbar?
K_O_P K_O_P

2012/4/6

#
Is there really nobody, who can help me?
davmac davmac

2012/4/6

#
tkiesel gave you a good starting point. Have a look in the Java API documentation on the Toolkit class - you can get the screen dimensions, resolution, and insets, which is enough to calculate all you need. Height (inches) = height (pixels) * resolution (pixels/inch) etc.
ttamasu ttamasu

2012/4/6

#
What tkiesel said works... All you need is the toolkit. Here is simple mock up, for instance: ---------------------- import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Dimension; import java.awt.Toolkit; /** * Write a description of class goo here. * * @author Takashi * @version 1 */ public class goo extends World{ public goo(){ super((int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(), (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight(),1); //Debug System.out.println("Debug: World Dimensiions = (" + getWidth()+","+ getHeight()+")"); } } ------------------ cheers, Takashi
You need to login to post a reply.