0

When I create a Canvas and a JFrame, then put the canvas onto the JFrame.

With this code

final Graphics g = Display.getBufferStrategy().getDrawGraphics();
g.setColor(Color.red);
g.fillRect(0, 0, 480, 360);
g.dispose();
Display.getBufferStrategy().show();

However when I put the code in

The drawing only occurs whenever its's in a loop.

This isn't a huge problem since it would be in a loop anyways, but it's annoying having to have it in a loop to have it draw/keep the image on the frame

Please someone help me.

Thanks.

Anthony Sasse
  • 64
  • 1
  • 6
  • Start by having a look at [`BufferStrategy`](http://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferStrategy.html) and [BufferStrategy and BufferCapabilities](https://docs.oracle.com/javase/tutorial/extra/fullscreen/bufferstrategy.html) which provides a number of excellent examples – MadProgrammer May 01 '16 at 03:53
  • For [example](http://stackoverflow.com/questions/34689176/bufferstrategy-not-showing-on-java-awt-frame/34689291#34689291), [example](http://stackoverflow.com/questions/35516191/what-is-the-correct-way-to-use-createbufferstrategy/35516500#35516500), [example](http://stackoverflow.com/questions/29000635/why-doesnt-my-screen-turn-red/29000677#29000677) – MadProgrammer May 01 '16 at 03:55
  • It might be useful to show the loop where the code works as intended. – Poriferous May 01 '16 at 19:26

0 Answers0