aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Canvas vs Applet painting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Canvas vs Applet painting" Watch "Canvas vs Applet painting" New topic
Author

Canvas vs Applet painting

Hydra Iris
Greenhorn

Joined: Jun 21, 2006
Posts: 13
Hi,

Can anyone tell me what is the advantages of using Canvas to paint(shape eg. rectangle, oval, line) compare to using Applet(appln not using web browser).

Thank You
Hydra
Keenan Staffieri
Greenhorn

Joined: Jul 22, 2006
Posts: 23
you use canvas to paint for applications. you use applet for web browser. But you have to use applet if you want people to use your game on your website or someone else's immeditaly. you must use appletview to see applets offline. but canvas will paint just like applet does but possibly faster if you use openGL on canvas.
Hydra Iris
Greenhorn

Joined: Jun 21, 2006
Posts: 13
Mm......Still need help

Let me rephrase my questions:
My concern are drawing on an applet panel itself and drawing on Canvas.

My appln don't need to run on a web-browser, nor a game program. Is just a simple program full of shapes eg. oval, rects, lines, circles, etc., overlapping each other To draw these I can choose to draw directly on the applet panel or by extending Canvas class.

So, what I wants to know is which is the best method to use - using Applet or extends Canvas. And why too.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42583
    
  65
If it isn't running in a browser, then you should not use an applet. It doesn't work as you would expect outside of a browser/appletviewer environment. So the Canvas is really the only way to go.


Ping & DNS - my free Android networking tools app
Hydra Iris
Greenhorn

Joined: Jun 21, 2006
Posts: 13
But is not wrongly to paint on the applet panel right?

I came across a graph project which plot on an applet. This project (not meant for web browser) retrieve xy coordinates from the mdb file and draw on the applet's panel. It worked fine.

No canvas class was used at all. The main problem is - loading slow. So, I was wondering, will it be better if the plotting was done by extending canvas. Will the loading performance improved?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42583
    
  65
If this isn't an applet, then, yes, it is wrong to use an Applet. But Applet extends Panel, and since the extra functionality isn't used, you could just use a Panel.

Offhand I'm not sure why using Canvas vs. using Panel (or Applet) should make a big performance difference. Have you done some comparison timings with your application?
Hydra Iris
Greenhorn

Joined: Jun 21, 2006
Posts: 13
Nope, never compare the 2 method.

I just want to confirm the performance of loading the graph is not due to the painting in applet or canvas.

Thank for your help.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

My take on it is this - use a Canvas instead of drawing on the Applet itself. Why? Separation of concerns - have the applet simply deal with providing the "run in a webpage" capability, and how to get resources. Have the canvas deal with what canvas is good for - painting.

This way, it's easier to test each part separately, and if you ever need to "re-target" your application to run stand-alone, rather than as an applet, you've already separated the painting from the applet code - so it's much easier.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Hydra Iris
Greenhorn

Joined: Jun 21, 2006
Posts: 13
Noted.....Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Canvas vs Applet painting