• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Drawing

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
AKEEL MALIK
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know how to draw using paint method to a panel or a canvas.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to get the container's graphics context and then load the image or any graphics element onto the particular container.

Example here:

 
AKEEL MALIK
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do I create a seperate canvas or Jpanel class
 
Ramakanth NVL
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
AKEEL MALIK
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic