import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; public class Kulgur extends JApplet implements Runnable, KeyListener{ SisseLugeja andmed=new SisseLugeja(); BufferedImage taust=new BufferedImage(600,600,BufferedImage.TYPE_INT_RGB); int[] x=andmed.x; int[] y=andmed.y; int[] l=andmed.l; int[] p=andmed.p; int n=andmed.i; int kx=0, ky=0; //kulguri x, y asukoht; public Kulgur(){ addKeyListener(this); new Thread(this).start(); } public void paint(Graphics g){ Graphics graafika=this.taust.getGraphics(); graafika.setColor(Color.white); graafika.fillRect(0,0,getSize().width,getSize().height); graafika.setColor(Color.black); for(int i=0;i=(y[i]-30)&&(250+ky)<=(y[i]+p[i]))) katse=1; } if(katse==1){ kx=kx; } else kx-=5; katse=0; } if(kood==KeyEvent.VK_UP){ for(int i=0;i=(x[i]-30)&&(250+kx)<=(x[i]+l[i]))) katse=1; } if(katse==1) ky=ky; else ky-=5; katse=0; } if(kood==KeyEvent.VK_DOWN){ for(int i=0;i=(x[i]-30)&&(250+kx)<=(x[i]+l[i]))) katse=1; } if(katse==1) ky=ky; else ky+=5; katse=0; } if(kood==KeyEvent.VK_RIGHT){ for(int i=0;i=(y[i]-30)&&(250+ky)<=(y[i]+p[i]))) katse=1; } if(katse==1) kx=kx; else kx+=5; katse=0; } } public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} public void run(){ while(true){ try{Thread.sleep(10);}catch(Exception kala){} repaint(); } } }