i getting error on getdocumentbas(). is there a easy way to display image on screen???

  public class Player 
    {
    private Image mario;

public Image getPlayerImage()
        { return mario.getImage(); }

        public void init()
        {        
            mario = new Image(getDocumentBas(),"Image/player_walk_right.GIF");
        }


        public void paint(Graphics g) 
        {
            g.drawImage(mario,x,y,this);
        }


}

i think following is useful to you.

Image image;
public void init() {
        System.out.println(getDocumentBase());
        image = getImage(getDocumentBase(),"logo.png");
    }
    public void paint(Graphics g) {
        g.drawImage(image, 0, 0, this);
    }

Also extends Applet in class Player.
I hope this might be working.

i am getting error on "getImage"

i say create getImage method or change to Image

let me repost my code: i have Main and Player class
my Player class:

public class Player extends Applet
{
Image mario;

public Player(int ix, int iy)
    {
        x = ix;
        y = ix;
    }   

        public Image getPlayerImage()
        { return mario.getImage(); }

        public void init() 
        {
            mario = new getImage(getDocumentBase(),"C:\\Users\\Ikhlas\\Pictures\\JAVAIMAGES\\CH1.png");
        }

        /*** paint method ***/
        public void paint(Graphics g) 
        {
            g.drawImage(mario, 0, 0, this);
        }/*** paint method ***/
}






my Main class:
public class Main extends Applet implements Runnable, KeyListener

{
private Player player_class;


public void paint(Graphics g) 
    {
        player_class.paint(g);

}

Edited 4 Years Ago by hwoarang69

 public Image getPlayerImage()
{ return mario.getImage(); }

mario already is an Image, so you just need to return it "as-is"

 public Image getPlayerImage()
{ return mario; }

When you initialise mario you have specified both a document base, and a fully-qualified path/file starting at c:
YOu should have one ofr the other of those, not both. For an applet it's the document base you need, the other paramter should just be the file name (and it's dir if that's a sub-dir of the document base directory). As jalpesh suggested, if you are not sure you should print the document base to find out exactly which dir it refers to

private Image getImage() {
    return player_image;
}

    public void init() 
    {
        player_image =getImage(getDocumentBase(),"player_walk_right.gif");  
    }

error - The method getDocumentBase() is undefined for the type Player

Edited 4 Years Ago by hwoarang69

This question has already been answered. Start a new discussion instead.