import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.util.*; public class HiirPall6 extends Applet implements MouseListener, Runnable{ double x, y, allserv=200, r=10; double samm=0, sammumuutus=0.5; boolean algus=true; Label silt1=new Label(); Label silt2=new Label(); Label silt4=new Label(); Label silt3=new Label(); int pihtas=0, moodas=0, palle=0; long algaeg=new Date().getTime(); Panel sildipaneel=new Panel(new GridLayout(1, 4)); Object luba=new Object(); public HiirPall6(){ setLayout(new BorderLayout()); sildipaneel.add(silt1); sildipaneel.add(silt2); sildipaneel.add(silt3); sildipaneel.add(silt4); add(sildipaneel, BorderLayout.SOUTH); addMouseListener(this); } void kukuJuhuslikustKohast(){ samm=0; synchronized(luba){ x=Math.random()*getWidth(); y=0; } palle++; silt3.setText("Palle: "+palle); } public void mousePressed(MouseEvent e){ int hx=e.getX(), hy=e.getY(); double xkaugus=hx-x, ykaugus=hy-y; if(algus){ kukuJuhuslikustKohast(); new Thread(this).start(); algus=false; } else { if(Math.sqrt(xkaugus*xkaugus+ykaugus*ykaugus)allserv){ samm=-0.8*Math.abs(samm); } } } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String[] arg){ Frame f=new Frame("Kukkuv pall"); f.add(new HiirPall6()); f.setSize(300, 300); f.setVisible(true); } }