[英]Circle not moving Java applet
我试图让自己的圈子动起来,以便我可以继续让我的小applet游戏上学,但是由于某种原因,它不动并且我不知道为什么。
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
}
}
您没有在循环中更新x
和y
//thread info
while (true){
repaint();
x += dx;
y += dy;
//rest the same
}
您还误导了destroy()- public void destory()
destory()-应该是public void destroy()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.