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);
  System.out.println("x="+x+" y="+y);
}
public void joonista(){g.drawString(s, Math.round(x), Math.round(y));
 //System.out.println("x="+x+" y="+y);
 }
public void joonista(Color c){
Color co=g.getColor();
g.setColor(c);
joonista();
g.setColor(co);
}
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=(float)Math.random()*5; sy=(float)Math.random()*5;} 
public void servliigu(){
 if(x+sx+sp>400)sx=-Math.abs(sx); if(x+sx<10)sx=Math.abs(sx);
 if(y+sy>350)sy=-Math.abs(sy); if(y+sy<20)sy=Math.abs(sy);
 edasi();
}
}
