Drawing over an awt canvas

Page 1 of 1

12 Replies - 541 Views - Last Post: 17 June 2010 - 09:15 PM Rate Topic: -----

#1 Manbearpig101  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 62
  • Joined: 17-June 10

Drawing over an awt canvas

Posted 17 June 2010 - 07:53 PM

Hey, how would I take an awt canvas, and draw over it with another canvas WHILE keeping the old canvas?
Is This A Good Question/Topic? 0
  • +

Replies To: Drawing over an awt canvas

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10595
  • View blog
  • Posts: 39,236
  • Joined: 27-December 08

Re: Drawing over an awt canvas

Posted 17 June 2010 - 07:56 PM

As Canvas is a Component, you can add() another Canvas on top of it, and draw that way. However, with Java 1.5 and Java 6, it is a much better to use Swing Components to accomplish your goal, as Swing has more features than AWT for painting and does not rely on the system for painting.
Was This Post Helpful? 0
  • +
  • -

#3 Manbearpig101  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 62
  • Joined: 17-June 10

Re: Drawing over an awt canvas

Posted 17 June 2010 - 08:06 PM

I added my own canvas, but the other canvas paints over my canvas. Not sure what to do..
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Drawing over an awt canvas

Posted 17 June 2010 - 08:09 PM

Not a 100% true Macos
Canvas are the only component for which you can invoke the createBufferStrategy() method if you want to draw of screen.
Mostly used in game programming when you draw of screen (that might take some time) and when your drawing is done, you just switch which Canvas is shown avoiding all possible flickering.

If everybody were using Canvas for drawing, we wouldn't have all these flickering questions in the forum.

This post has been edited by pbl: 17 June 2010 - 08:52 PM
Reason for edit:: Typo

Was This Post Helpful? 1
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10595
  • View blog
  • Posts: 39,236
  • Joined: 27-December 08

Re: Drawing over an awt canvas

Posted 17 June 2010 - 08:09 PM

There is a reason for using Swing instead of AWT Canvas. What exactly are you trying to accomplish here with your painting? If you can give us more details, it would be easier for us to suggest better ideas and alternatives. :)

Edit: pbl had additional information that invalidated my first sentence.

This post has been edited by macosxnerd101: 17 June 2010 - 08:11 PM

Was This Post Helpful? 1
  • +
  • -

#6 Manbearpig101  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 62
  • Joined: 17-June 10

Re: Drawing over an awt canvas

Posted 17 June 2010 - 08:22 PM

View Postmacosxnerd101, on 17 June 2010 - 07:09 PM, said:

There is a reason for using Swing instead of AWT Canvas. What exactly are you trying to accomplish here with your painting? If you can give us more details, it would be easier for us to suggest better ideas and alternatives. :)

Edit: pbl had additional information that invalidated my first sentence.


My friend is taking an awt based applet (a game). He wants to draw onto that canvas.
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Drawing over an awt canvas

Posted 17 June 2010 - 08:25 PM

All sins forgiven:)

And also, if you have performance issues, Canvas is the fastest component ever written. That is why they never made a JCanvas.

View PostManbearpig101, on 17 June 2010 - 09:22 PM, said:

My friend is taking an awt based applet (a game). He wants to draw onto that canvas.

Post your code. If there is no performance issues macosxnerd101 suggestion to go to Swing is still valid.
Was This Post Helpful? 1
  • +
  • -

#8 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10595
  • View blog
  • Posts: 39,236
  • Joined: 27-December 08

Re: Drawing over an awt canvas

Posted 17 June 2010 - 08:39 PM

Quote

And also, if you have performance issues, Canvas is the fastest component ever written. That is why they never made a JCanvas.

Probably also the reason Sun adapted Canvas for Java ME for mobile devices.
Was This Post Helpful? 0
  • +
  • -

#9 Manbearpig101  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 62
  • Joined: 17-June 10

Re: Drawing over an awt canvas

Posted 17 June 2010 - 08:41 PM

View Postpbl, on 17 June 2010 - 07:25 PM, said:

All sins forgiven:)

And also, if you have performance issues, Canvas is the fastest component ever written. That is why they never made a JCanvas.

View PostManbearpig101, on 17 June 2010 - 09:22 PM, said:

My friend is taking an awt based applet (a game). He wants to draw onto that canvas.

Post your code. If there is no performance issues macosxnerd101 suggestion to go to Swing is still valid.


As much as I like posting code, my friend is impartial to me posting it.

=\
Was This Post Helpful? 0
  • +
  • -

#10 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10595
  • View blog
  • Posts: 39,236
  • Joined: 27-December 08

Re: Drawing over an awt canvas

Posted 17 June 2010 - 08:42 PM

Not much we can do to help if you can't post the code.
Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Drawing over an awt canvas

Posted 17 June 2010 - 08:46 PM

View PostManbearpig101, on 17 June 2010 - 09:41 PM, said:

As much as I like posting code, my friend is impartial to me posting it.

So "mechanics fix my car but do not open the hood" :)
But your friend might be right, the FBI, the CIA, the Mossad, the North Corean secret services, the RCMP, the French 2nd bureau, even the Lybians monitor this site everyday so they can see if they cab steal cheap code.

This post has been edited by pbl: 17 June 2010 - 08:55 PM
Reason for edit:: Typo

Was This Post Helpful? 0
  • +
  • -

#12 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Drawing over an awt canvas

Posted 17 June 2010 - 08:54 PM

View Postmacosxnerd101, on 17 June 2010 - 09:39 PM, said:

Quote

And also, if you have performance issues, Canvas is the fastest component ever written. That is why they never made a JCanvas.

Probably also the reason Sun adapted Canvas for Java ME for mobile devices.

Why re-inventing the wheel. Cheap and easy to implement simple component with a very low footprint.
Was This Post Helpful? 0
  • +
  • -

#13 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10595
  • View blog
  • Posts: 39,236
  • Joined: 27-December 08

Re: Drawing over an awt canvas

Posted 17 June 2010 - 09:15 PM

Actually, the J2ME Canvas is different to work with in key ways in comparison to the J2SE AWT Canvas. They're probably really similar in design though.

@Manbearpig101: I'm going to close this thread since you aren't able to post code, so there's no reason to keep it open. If this changes, feel free to PM me, along with a link to this thread, and I'll be happy to reopen. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1