import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class pallike2 extends Applet implements ActionListener{ int nr=30; int mitu=0; int x=0; int oota=50; Button kiiremini=new Button(" Kiiremini "); Button aeglasemalt=new Button(" Aeglasemalt "); Button paremale=new Button(" Paremale "); Button vasakule=new Button(" Vasakule "); public pallike2(){ add(kiiremini); kiiremini.addActionListener(this); add(aeglasemalt); aeglasemalt.addActionListener(this); add(paremale); paremale.addActionListener(this); add(vasakule); vasakule.addActionListener(this); } public void actionPerformed(ActionEvent ev){ x=0; int a=150; int b=150; mitu=1; Graphics g=this.getGraphics(); if(ev.getSource()==paremale){ //ring liigub paremale for(int x=40; x<100; x=x+2){ g.setColor(Color.blue); g.drawOval(a, b, nr, nr); try{Thread.sleep(oota);}catch(Exception e){} g.setColor(Color.white); g.drawOval(a, b, nr, nr); a=a+10; } } if(ev.getSource()==vasakule){ //ring liigub vasakule for(int x=40; x<130; x=x+2){ g.setColor(Color.blue); g.drawOval(a, b, nr, nr); try{Thread.sleep(oota);}catch(Exception e){} g.setColor(Color.white); g.drawOval(a, b, nr, nr); a=a-10; } } if(ev.getSource()==aeglasemalt){ oota=oota+10; } if(ev.getSource()==kiiremini){ oota=oota-10; } repaint(); } public static void main(String[] argumendid){ Frame f=new Frame(); f.add(new pallike2()); f.setSize(400, 400); f.setBackground(Color.blue); f.setVisible(true); } }