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);
        }


}

Recommended Answers

All 5 Replies

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);

}
 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

i just geting a error at getDocumentBase()

i am not sure what is that

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.