2

As can be seen from the Canvas class and the JFrame class, the methods related to BufferStrategy (of the Canvas and of the JFrame) don't come from the same parent. The createBufferStrategy of JFrame for example, is inherited by Window, which is not a parent of Canvas, while Canvas implements its own. Actually, their last common ancestor is Component which doesn't have this method.

So I'm wondering whether the functionality of the two is the same, and whether my program will behave the same when replacing the createBufferStrategy/getBufferStrategy of the Canvas with the createBufferStrategy/getBufferStrategy of the Window.

I've decided to do this "replace move" because I read yesterday JPanel is no slower than Canvas here: Canvas and InputMap.

So I basically want to add JPanel instead of Canvas now.
When I started coding, my first choice was Canvas because of this:
tutorial on youtube. So you can see more or less my code there, even though I've done a few changes, as they are not related to this topic.

Community
  • 1
  • 1
user2773143
  • 167
  • 2
  • 10

2 Answers2

0

Some time ago, Canvas and Window inherited the createBufferStrategy() and getBufferStrategy() methods from Component, but now oracle has change it because they just wanted Window and Canvas classes(and their subclasses) have these methods, not the other COmponent subclasses.

So yes, there are not differences between the createBufferStrategy() and getBufferStrategy() methods from Canvas and Window, and you can use either CanvasObject.getBufferStrategy() and JFrameObject.getBufferStrategy()

Le Ploit
  • 43
  • 12
0

First things first in Java when you are creating a GUI it is usually recommended to use swing instead of AWT. To answer your question, no creating a buffer strategy for a JFrame or a JPanel will not function the way you want it to I just tried it and it doesn't seem to work at all actually. All swing components are already double buffered so it is unnecessary to create a bufferstrategy. I have skimmed the videos you provided in that link and I can see where you are going with this. I recommend looking at the first answer on this page that for some reason is not the excepted answer but it extremely helpful.

Community
  • 1
  • 1
X_Wera
  • 160
  • 10