Forums Register Login

Drawing

+Pie Number of slices to send: Send
I have go a JApplet that displays a Image through tha Paint method. Can Anyone please tell me how to draw the image in a panel and also on canvas.
+Pie Number of slices to send: Send
The procedure for drawing an image on a java.awt.Panel or on a Canvas is much the same as shown below. It is not recommended to mix AWT and Swing so you use a java.awt.Applet vis–a–vis JApplet and the Panel/Canvas paint method with signature

In AWT drawing you may find value in overriding the update method; sometimes like this to avoid flickering

but this will vary according to what you are doing and want to achieve. Swing painting tends to be easier than painting in the AWT. The override of the getPreferredSize method is for the JScrollPane. You can use the setPreferredSize instead if you like. setPreferredSize is part of the Component api (okay for use in AWT) as of j2se 1.5
+Pie Number of slices to send: Send
Do you know how to draw using paint method to a panel or a canvas.
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
You need to get the container's graphics context and then load the image or any graphics element onto the particular container.

Example here:

+Pie Number of slices to send: Send
Do I create a seperate canvas or Jpanel class
+Pie Number of slices to send: Send
You have to getgraphics() for which ever panel you are want to draw into.

Say for eg.
You are adding imagepanel to the applet which I suppose u would have done this way.


When u draw an image using pgraphics the (0,0) position is wherever the imagepanel starts. And similarly for cgraphics. Hope its clear to u now.
+Pie Number of slices to send: Send
Can you please tell me why when I invoke the paint method my panels and Menubar and sometimes buttons are painted over.
It'll paint the image in the panel but ma other components and panel will be jst covered white
The City calls upon her steadfast protectors. Now for a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1832 times.
Similar Threads
converting png to tiff and character recognition with tesseract
Loading image file
Unsupported Color Conversion Request
Easy one
Getting rid of Java Icon on the upper left hand corner
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:18:31.