Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: error in print image onto applet

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default error in print image onto applet

    so i have two class.
    1 = Main.java - 2 = Player.java
    AND
    my folder tree

    -src
    -images
    player_walk_right.gif
    -Main.java
    -Player.java



    Player.java
    public class Player 
    {
        Image player_image = getImage(getDocumentBase(),"player_walk_right.gif");
     
        /*** constructor Method ***/
        public Player()
        {
            //empty constructor 
        }
        public Player(int ix, int iy)
        {
            x = ix;
            y = ix;
        }   
     
        /*** get/set method ***/
            public Image  getImages() 
            { return player_image; }
     
        /*** paint method ***/
            public void paint(Graphics g) 
            {
                g.drawImage(player_image, 0, 0, null);
            }/*** paint method ***/
    }/*** end of class ***/


    Main.java :
    public class Main extends Applet implements Runnable
    {
     
        /*** start method ***/
        @Override
        public void start()
        {
            player_class = new Player();
            Thread thread = new Thread(this);
            thread.start();
        }/*** end of start method ***/
     
        /*** run method ***/
        public void run()
        {
            while(true) //player moves
            {
                player_class.update(this);
                repaint();
                try
                {
                    Thread.sleep(17);
                }
                catch(InterruptedException e)
                {
                    e.printStackTrace();
                }
            }
        }/*** end of run method ***/
        /*** paint method ***/
        @Override
        public void paint(Graphics g) 
        {
            player_class.paint(g);  //call Player class, which will draw player
        }/*** end of paint method ***/
     }


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


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: error in print image onto applet

    Quote Originally Posted by hwoarang69 View Post
    error - The method getDocumentBase() is undefined for the type Player
    any idess?
    The error is telling you exactly what's wrong. You are calling getDocumentBase() in player without calling it on any object or class, as if the Player class has this method itself, and the error is telling, that the Player class does not in fact have this method. I don't do applet programming, but I seem to remember that this method is a method of Applet. Regardless, check the API as it will tell you if this is so or not.

Similar Threads

  1. Applet Image Reading
    By 77times in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 29th, 2012, 11:25 PM
  2. Applet array paint/print question
    By allhuber in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 30th, 2012, 08:42 AM
  3. Problem Applet Error
    By mohsendeveloper in forum Java SE APIs
    Replies: 24
    Last Post: January 19th, 2012, 04:00 PM
  4. Error while running Applet
    By rameshiit19 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: August 1st, 2011, 04:02 AM
  5. Need help on print , scrollbar for my applet
    By Anandprasad in forum Member Introductions
    Replies: 2
    Last Post: May 12th, 2011, 09:00 AM