• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

placing an image into a panel

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
perhaps someone can help me out here...
I made an applet that displays a jpeg image as a
background. I placed another image in a specified
position using the following code:
private Image buffer;
private Graphics gBuffer;
Image background, obj;
public void init()
{
//create graphics buffer the size of the applet
buffer= createImage(size().width, size().height);
gBuffer= buffer.getGraphics();
background= getImage(getCodeBase(), "bubble.jpg");
obj= getImage(getCodeBase(), "ball.gif");
}
........//from run method
gBuffer.drawImage(background,0,0,this);
gBuffer.drawImage(obj,x,150,this);
Problem is, for my new applet, I want to place an image
into a panel....I can't use the add method....how do
you mix components with Graphics class?
any ideas? confused Bob
[ February 12, 2004: Message edited by: Bob Chandler ]
[ February 12, 2004: Message edited by: Bob Chandler ]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An image isn't a component, so you can't use add() to put an image on a panel. You have to override paint() and paint the image like you have above. Of course, you can make methods that will take an image and draw them on a Panel... something like this-
 
Bob Chandler
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Nate,
didn't get what you meant at first....
was washing the dishes and mulling it all over when
light dawned...
...create an instance of ImagePanel class in place
of the plain old Panel instance...
...when it's overridden version of paint is called,
the image is drawn in the ImagePanel!
I tried it,it worked and I thank you
 
Don't MAKE me come back there with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic