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: getDocumentBase error

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

    Default getDocumentBase error

    note i want to do this code in background class. not in main class.
    so i have a main class and a background class.

    getting error at
    url = getDocumentBase();
    also getting error at
    getImage
    drawImage


    background class
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Rectangle;
    import java.net.URL;
     
    //#2
    public class Background 
    {
    	/* background image */
    	private URL url;
    	 private Image background_image1;
    	 private double bX1 = 0;
    	 private double bDX1 = 0.3;
     
    	 private Image background_image2;
    	 private double bX2 = 0;
    	 private double bDX2 = 1;
     
    	 private Main main_class = new Main();
     
    	/*** constructor Method ***/
    	public Background() 
    	{
    	}	
     
    	public void init() 
    	{
    		try
    		{
    			url = getDocumentBase();
    		}
    		catch(Exception e)
    		{
    		}
    		background_image1 = getImage(url, "image/background/background.png");
    		background_image2 = getImage(url, "image/background/background2.png");
    	}/*** end of init method ***/
     
     
     
    	/*** paint method ***/
    	public void paint(Graphics g) 
    	{
    		g.setColor(new Color(15, 77, 147));  //sky
    		g.fillRect(0,0,main_class.getWidth(), main_class.getHeight()); //sky
    		g.drawImage(background_image1, (int)bX1, 0, this);//backgroung image
    		g.drawImage(background_image1, (int)bX1 + main_class.getWidth(), 0, this);//backgroung image
    	}/*** paint method ***/
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: getDocumentBase error

    I see nothing in your code which specifies where these methods are defined...I'm presuming you are trying to access the methods of Applet, so you need a reference to this class to call its methods.

Similar Threads

  1. Please! Help me to this error "ERROR CANNOT FIND SYMBOL"
    By mharck in forum Object Oriented Programming
    Replies: 8
    Last Post: July 3rd, 2012, 09:20 AM