0

I am trying to get my circle to move so I can keep devolping my small applet game for school, but for some reason Its not moving and I can not figure out why.

public class StartingPonit extends Applet implements Runnable{

    int x = 0;
    int y = 0;
    int dx = 1;
    int dy = 1;
    int radis = 20;
    private Image i;
    private Graphics doubleG;

    @Override
    public void init() {
        setSize(800,600);

    }
        @Override
    public void start() {
        Thread thread = new Thread(this);
        thread.start();  // thread info;
    }
        @Override
    public void run() {
        x =+ dx;
        y =+ dy;
        //thread info
        while (true){
        repaint();
        try {
            Thread.sleep(17);
        } catch (InterruptedException ex) {
            Logger.getLogger(StartingPonit.class.getName()).log(Level.SEVERE, null, ex);
        }
        }
    }
        @Override
    public void stop() {

    }
    public void destory() {

    }
    @Override
    public void update(Graphics g) {
        if(i == null){
            i = createImage(this.getSize().width,getSize().height); //double bbuffering
            doubleG = i.getGraphics();
       }
        doubleG.setColor(getBackground());
        doubleG.fillRect(0,0, this.getSize().width,this.getSize().height);

        doubleG.setColor(getForeground());
        paint(doubleG);

        g.drawImage(i, 0, 0, this);
    }
    @Override
        public void paint(Graphics g) {
            g.setColor(Color.BLACK);
            g.fillOval(x-radis, y-radis, radis*2, radis*2); //size of object

    } 

}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Rune
  • 1
  • 2
    I don't know what your intention is - but you move the circle once and then start your loop, so it will only move once – Ford Filer Jun 19 '14 at 18:12
  • In order to get the circle moving, x and y need to change. Doesn't that mean that the code to alter x and y should be at a slightly different location in your code? – fvu Jun 19 '14 at 18:12
  • 1
    1) Why code an applet? If it is due to spec. by teacher, please refer them to [Why CS teachers should stop teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why AWT rather than Swing? See my answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. – Andrew Thompson Jun 20 '14 at 09:37

2 Answers2

0

You aren't updating x and y in your loop

//thread info
while (true){   
    repaint();
     x += dx;
     y += dy;
   //rest the same
}
dkatzel
  • 31,188
  • 3
  • 63
  • 67
0

You have also mispelt destroy() -- public void destory() -- should be public void destroy()

DavidPostill
  • 7,734
  • 9
  • 41
  • 60