Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to draw an image in an applet?

 
priya aravind
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to write code to draw an image in an applet window. Is there any way to do it using the awt and graphics class?
Thanks.
Priya
 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
yes, this can be done.
rewrite the paint(Graphics g) method of the component (eg. Canvas) you want to draw to. you can find some examples on the net eg.
draw aplet
it consist of the files:
Dot
Applet
and
Canvas
this one is without comments....but you should understand it.
k

or do you want to draw an image like jpg, gif... ?

[This message has been edited by karl koch (edited November 29, 2001).]
 
Michael Bruesch
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by priya aravind:
I am trying to write code to draw an image in an applet window. Is there any way to do it using the awt and graphics class?
Thanks.
Priya

Create an Image reference and a Graphics reference like so:
Image buffer;
Graphics bufferg;
Then create objects like so:
buffer = createImage (getSize ().width, getSize ().height);
// or whatever size you want the image to be
bufferg = buffer.getGraphics ();
Then in your paint method, draw everything using the bufferg reference (which will draw everything on the image) and finally in your paint method, draw the image to the ImageObserver:
g.drawImage (buffer, 0, 0, this);
// this = ImageObserver reference
Hope that's what you're looking for
------------------
Michael J Bruesch
Codito, ergo sum...
I code, therefore I am.
My Java Games, I'm quite proud
 
priya aravind
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Karl and Michael.The tips are very helpful.I wanted to create a paintbrush -like editor.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic