I wrote these code in a class which extends Canvas. (please have a look at the pictures at these links if you don't want to read, i can't post pictures directly because of stackoverflow reputation or something) http://tinypic.com/r/oaw3u8/5 http://tinypic.com/r/24g9ldz/5
final static int WIDTH = 800;
final static int HEIGHT = 600;
Dimension SIZE = new Dimension(WIDTH, HEIGHT);
Game() {
setPreferredSize(SIZE);
**
**
*
*
}
public void render() {
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
g.setColor(Color.cyan);
Graphics2D g2 = (Graphics2D) g;
**g.fillRect(0, 0, getWidth(), getHeight());**
g.dispose();
bs.show();
}
question is about the double-stared line of code, which is used for refreshing the screen by drawing a screen-size rectangle.
**at the first time, my code was
g.fillRect(0,0,WIDTH,HEIGHT);
then i notice the balck rectangle was smaller then the screen. there was a minor,about 1 inch, margin at the right inside of the frame.(i might use "margin" wrong but i hope you get what i mean)
so i used getWidth(),getHeight() instead of using the exact variable WIDTH and HEIGHT.
and it worked well,
i don't know the reason why ?
please help me why is this happening, are variable not accurate in this situation? or what .
thank you very much