Solved

Canvas and Panel

Posted on 2002-06-30
3
283 Views
Last Modified: 2012-05-04
Since you can use the Graphics methods on a Panel, what is the advantage of using a Canvas instead of a Panel to display an image, for example?
0
Comment
Question by:HanRui
3 Comments
 
LVL 9

Expert Comment

by:Ovi
Comment Utility
Panel is a container, canvas is a component. Of course both of them have as superclass Component, but they coming from different class tree paths(roots). On a Panel you can add components which meens that you can overlap what are you doing in the paint method; this can be a good think, or a bad one, depending on your application type/design. Canvas on the other hand is "specialized" for graphic operations. Basically there is no difference from the paint method point of view. All is very depending of your application specifications and needs.
0
 

Author Comment

by:HanRui
Comment Utility
Thanks, but this still this doesn't explain to me the need for a Canvas class since Panel can do everything that Canvas can do.
0
 
LVL 2

Accepted Solution

by:
allie earned 100 total points
Comment Utility
The advantage of using a Canvas for graphics (as opposed to a Panel), is that Canvas allows more flexible graphics programming.  For example, you can set a GraphicsConfiguration when creating a Canvas (whereas in a Panel you could set the Layout).  Canvas allows you to use more advanced graphics, utilize more periphery interaction (like with printers, moniters, and mulit-screen environments), and have better (optimal) trapping of input events from the user related to graphics.  (Like letting the user draw lines in the graphics area.)  I've never even tried to let a user draw using the mouse on a Panel (for instance), and if you can even do it I'm sure you'd need some extra code to handle it that would be unnecessary in Canvas.

allie
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now