public class Gamefarme2 extends Frame {
Image img = gameUtil.getImage("imges/game.png"); //加载图片
public void launchFrame ()
{
setSize(600,600);
setLocation(100,100);
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
private double x,y=100;
private boolean left;
@Override
public void paint(Graphics g) { //加载窗口
super.paint(g);
new PainThread().start();//启动重画线程
g.drawImage(img,(int)x,(int) y, null);
if(left){
x-=1;
}
else {
x+=1;
}
if (x>500-30) {
left=true;
}
if(x<0){
left=false;
}
}
class PainThread extends Thread//重画线程
{
public void run() {
while(true){
repaint();
try {
Thread.sleep(5000);
break;
} catch(InterruptedException ie) {}
}
}
}
public static void main(String[] args) { // 主函数
Gamefarme2 gf= new Gamefarme2();
gf.launchFrame();
}
}