Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Canvas vs Applet painting

 
Hydra Iris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hydra Iris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hydra Iris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Noted.....Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic