10.8 補足:
マウスがクリックされた座標まで
『10歩』で移動するスレッド |
public void mouseClicked(MouseEvent e){ px=sx=x_start; py=sy=y_start; ex=e.getX(); ey=e.getY(); dx=(ex-sx)/10; dy=(ey-sy)/10; t = new Thread(this); t.start(); }
public void run(){ for(int i=0;i<10;i++){ try{ Thread.sleep(200); px+=dx; py+=dy; repaint(); }catch(Exception e){ e.printStackTrace(); } } x_start=px; y_start=py; } |
 |