Putting an Image inside a Panel

F

FuzzyLogic

I am writting an Applet (not a JApplet) and I have all the GUI ready,
with panels and panels inside panels. In one of this panels I need to
show an Image, but I can't work out how to do it. The image keeps
showing in the background of the applet, so the panels cover it. I have
tried:

Graphics gr=myPanel.getGraphics();
gr.drawImage(myImnage,0,0,null);

inside the paint() method, but It doesn't work.

Could you help me? I am just a beginner in Java.

Thanks
 
Z

zero

I am writting an Applet (not a JApplet) and I have all the GUI ready,
with panels and panels inside panels. In one of this panels I need to
show an Image, but I can't work out how to do it. The image keeps
showing in the background of the applet, so the panels cover it. I have
tried:

Graphics gr=myPanel.getGraphics();
gr.drawImage(myImnage,0,0,null);

inside the paint() method, but It doesn't work.

You should draw the image from within the panel's paint method, not the
applet's paint.

Panel myPanel = new Panel()
{
public void paint(Graphics g)
{
g.drawImage(myImage, 0, 0, null);
}
};

applet.add(myPanel);

I think this should work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top