aspose file tools*
The moose likes Beginning Java and the fly likes How to draw an image in an applet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to draw an image in an applet?" Watch "How to draw an image in an applet?" New topic
Author

How to draw an image in an applet?

priya aravind
Greenhorn

Joined: Nov 28, 2001
Posts: 2
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

Joined: May 25, 2001
Posts: 388
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

Joined: Sep 23, 2001
Posts: 158
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


Michael J Bruesch<br /><i>I code, therefore I am.</i>
priya aravind
Greenhorn

Joined: Nov 28, 2001
Posts: 2
Thanks Karl and Michael.The tips are very helpful.I wanted to create a paintbrush -like editor.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to draw an image in an applet?