What are the benefits of Canvas in AWT?

I searched a lot of sources, but still can not find a worthy explanation. Why should I use it, what is its β€œpurpose, and why is it different from JPanels, etc.?

+4
source share
3 answers

Canvas's specialty is that, like Window, it can provide customizable hardware accelerated double buffering and page turning. See BufferStrategy .

Canvas for painting, basically. It also serves as a panel for creating a custom AWT-based component, but unlike Panel, it cannot contain other components.

+3
source

In my opinion, Canvas is just an AWT Swing JComponent version. You should not use it directly unless you are doing a clean AWT program. Here you can find more information .

+3
source
 public class Canvas extends Component implements Accessible 

The Canvas component is an empty rectangular area of ​​the screen onto which the application can draw or from which the application can capture input events from the user. An application needs to subclass the Canvas class to get useful features, such as creating a custom component. The drawing method must be redefined to execute custom graphics on the canvas.

Canvas for painting, basically. It also serves as a panel for creating a custom AWT-based component, but unlike Panel, it cannot contain other components.

0
source

Source: https://habr.com/ru/post/1487108/


All Articles