Putting an Image inside a Panel

Discussion in 'Java' started by FuzzyLogic, Dec 17, 2005.

  1. FuzzyLogic

    FuzzyLogic Guest

    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
    FuzzyLogic, Dec 17, 2005
    #1
    1. Advertising

  2. FuzzyLogic

    zero Guest

    FuzzyLogic <> wrote in news:S6Wof.125974$yg1.108478
    @twister.auna.com:

    > 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.

    --
    Beware the False Authority Syndrome
    zero, Dec 17, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harry
    Replies:
    3
    Views:
    542
    Harry Singh
    Nov 10, 2003
  2. Saurabh
    Replies:
    6
    Views:
    4,528
    Chris Smith
    May 30, 2004
  3. HS1
    Replies:
    3
    Views:
    486
  4. HS1
    Replies:
    4
    Views:
    8,297
    Babu Kalakrishnan
    Dec 8, 2004
  5. muthukumar
    Replies:
    0
    Views:
    314
    muthukumar
    Apr 25, 2006
Loading...

Share This Page