import java.awt.Frame; import java.awt.event.*; import java.awt.Graphics; import java.awt.Color; import java.io.*; import java.lang.String; import java.lang.Integer; import java.lang.Runnable; public class Ring extends Frame implements Runnable{ static int komakoht; static int x1; static int y1; static int[] x=new int[5]; static int[] y=new int[5]; int ooteaeg=100; boolean veel=true; public Ring(){ // run(); try { koordinaadid(); } catch(Exception e){e.printStackTrace();} paint(); new Thread(this).start(); } public void koordinaadid() throws IOException{ BufferedReader sisse=new BufferedReader( new FileReader("ring.txt") ); String rida=sisse.readLine(); for(int i=0; i<5; i++){ komakoht=rida.indexOf(','); x1=Integer.parseInt(rida.substring(0, komakoht)); y1=Integer.parseInt(rida.substring(komakoht+1)); x[i]=x1; y[i]=y1; System.out.println("x = "+x1); rida=sisse.readLine(); }//for } public void paint(){ System.out.println("Oleme painti sees"); Graphics g=this.getGraphics(); if(g!=null){ for(int i=0; i<4; i++){ for(int j=0; j<10; j++){ g.setColor(Color.black); g.fillOval(x[i]+(x[i+1]-x[i])*j/10, y[i]+(y[i+1]-y[i])*j/10, 20, 20); try{ Thread.sleep(ooteaeg); } catch(Exception e){e.printStackTrace();} g.setColor(Color.white); g.fillOval(x[i]+(x[i+1]-x[i])*j/10, y[i]+(y[i+1]-y[i])*j/10, 20, 20); }//for }//for for(int j=0; j<10; j++){ g.setColor(Color.black); g.fillOval(x[4]+(x[0]-x[4])*j/10, y[4]+(y[0]-y[4])*j/10, 20, 20); try{ Thread.sleep(ooteaeg); } catch(Exception e){e.printStackTrace();} g.setColor(Color.white); g.fillOval(x[4]+(x[0]-x[4])*j/10, y[4]+(y[0]-y[4])*j/10, 20, 20); } } }//void paint public void run(){ while(veel){ paint(); try{ Thread.sleep(ooteaeg); } catch(Exception e){e.printStackTrace();} } } public static void main(String argumendid[]){ Frame f=new Ring(); f.setSize(300, 300); f.setVisible(true); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.out.println("Programmi ots"); System.exit(0); } }); }//void main }//class