import java.awt.*; import java.awt.event.*; public class pall extends Frame implements MouseListener,Runnable{ int px=337; int py=100; int ax=1; int ay=1; int xn,yn; String xsuund,ysuund; public pall(){ setTitle("Põrkav pall"); setSize(500,700); setVisible(true); addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); }//windowevent } //windowadapter ); //windowlistener addMouseListener(this); new Thread(this).start(); } public void run(){ while(true){ p6rka(); px=(ax*1+px); py=(ay*1+py); if (px>470){ ax=-1;} if (px<0){ ax=1;} if (py>670){ ay=-1;} if (py<0){ ay=1;} //nüüd vahesein: if(py==350){if(px<250){if(px>0){ ay=ay*(-1);}}} }//while }//run public void p6rka(){ Graphics g=getGraphics(); g.setColor(Color.white); g.fillRect(1,1,500,700); g.setColor(Color.blue); g.fillRect(0,350,250,5); g.setColor(Color.red); g.fillOval(px,py,30,30); //System.out.println("x:"+px+" y:"+py+" ax: "+ax+" ay "+ay); try{ Thread.sleep(1); }//try catch(Exception exp){ System.out.println("catch"); }//catch //System.out.println("public void p6rka"); } public void mousePressed(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseClicked(MouseEvent e){} public static void main(String argumendid[]){ new pall(); } }