This is my code in a applet :

import java.awt.*;
import java.applet.*;
import java.util.*;
import javax.swing.*;


public class BallMove extends Applet
{       Random r = new Random();
        private int x,x1,x2,x3 ;
        private int y,y1,y2,y3 ;
        private Image offImage;
        private Graphics offGraphics;
        private Image img;
        private ImageIcon img2;

  public void init()
  {
        offImage = createImage(500,500);
        offGraphics = offImage.getGraphics();
        img = getImage(getDocumentBase(),"img11.jpg");
        img2 =  new ImageIcon("img11.jpg");

  }
  public void paint(Graphics g)
  {     super.paint(g);
        img2.paintIcon(this,g,180,0);
        Color color =new Color(r.nextInt(256),r.nextInt(256),r.nextInt(256));

        y= r.nextInt(700);
        x=r.nextInt(1000);
        y1= r.nextInt(700);
        x1=r.nextInt(1000);
        y2= r.nextInt(700);
        x2=r.nextInt(1000);
        x3=r.nextInt(1000);
        y3=r.nextInt(700);
        g.setColor(color);
        g.fillOval(x,y,100,100);
        g.fillOval(x1,y1,100,100);
        g.fillOval(x2,y2,100,100);
        g.fillOval(x3,y3,100,100);
        delay(300);

        move();

        g.drawImage(offImage,0,0,this);
        offGraphics.fillOval(x,y,100,100);
        offGraphics.fillOval(x1,y1,100,100);
        offGraphics.fillOval(x2,y2,100,100);

  }
  public void delay(int milisecond)
  {
        try{
                Thread.sleep(milisecond);
           }catch (Exception e) {}
  }
  public void move()
  {

                x= x + 5;
                y= y +5;
                x1=x1+10;
                y1=y1+5;
                x2=x2-10;
                y2=y2-5;


                repaint();

  }
  public void update(Graphics g)
  {
        paint(g);
  }
}


Background is error when the ball moves. How to fix it ?

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to