Solved

Canvas and Panel

Posted on 2002-06-30
3
284 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
ID: 7121081
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
ID: 7121511
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
ID: 7122218
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

919 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

11 Experts available now in Live!

Get 1:1 Help Now