Solved

Canvas and Panel

Posted on 2002-06-30
3
285 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 104
allswap challenge 6 96
Java - Why doesn't this JFrame work 3 58
Way to decrease size of apk file 9 65
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

815 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