import java.awt.*;
public class sona{
 Graphics g; 
 String s;
 float x, y, sx, sy;
 int sp;
public sona(Graphics gr, String st, int kx, int ky){
 FontMetrics fm;
 g=gr; s=st; x=kx; y=ky; 
 fm=g.getFontMetrics();
 sp=fm.stringWidth(s);
}
public void joonista(){g.drawString(s, Math.round(x), Math.round(y));}
public void suund(int kx, int ky, int arv){sx=(kx-x)/(float)arv;
 sy=(ky-y)/(float)arv;}
public void jkoht(float kx, float ky){x=kx; y=ky; joonista();}
public void edasi(){x+=sx; y+=sy; joonista();}
public void varv(Color c){g.setColor(c);}
public void muudavarv(Color c){g.setColor(c); joonista();}
public void juhusiht(){sx=Math.random(); sy=Math.random();} 
public void servliigu(){
 if(x+sx+sp>500)sx=-Math.abs(sx); if(x+sx<0)sx=Math.abs(sx);
 if(y+sy>500)sy=-Math.abs(sy); if(y+sy<0)sy=Math.abs(sy);
 edasi();
}
}
