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


background class
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;

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() 
            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 ***/

Edited 4 Years Ago by Reverend Jim: Fixed formatting

Those methods are inherited from the Applet class, so you can call them if your class extends JApplet or Applet, but your Background class doesn't do that.

Edited 4 Years Ago by JamesCherrill

This article has been dead for over six months. Start a new discussion instead.