import java.applet.Applet; import java.awt.event.*; import java.awt.*; import java.util.Vector; public class m2ng2 extends Applet implements KeyListener{ Graphics g; int x=5, y=10; int rx=x-10, ry=y-10, xl=16, yl=16; public m2ng2(){ addKeyListener(this); } public void paint(Graphics g){ //ymbritsevad seinad g.drawLine(0, 20, 0, 80); //ü-a vasak sein g.drawLine(80, 0, 80, 80); //ü-a parem sein g.drawLine(0, 0, 80, 0); //p-v ylemine sein g.drawLine(20, 80, 80, 80); //p-v alumine sein //vasakult paremale g.drawLine(0, 20, 60, 20); //v-p g.drawLine(60, 40, 80, 40); //v-p g.drawLine(40, 60, 60, 60); //v-p g.drawLine(20, 80, 40, 80); //v-p //ylevalt alla g.drawLine(40, 20, 40, 60); //y_a g.drawLine(20, 40, 20, 80); //y_a g.drawLine(40, 40, 40, 60); //y_a g.setColor(Color.red); g.drawLine(x-5, y, x, y); } public void keyPressed(KeyEvent k){ int kood=k.getKeyCode(); if(kood==KeyEvent.VK_RIGHT){ x=x+5; if(x==20&&y>=40&&y<=80){ x=x-5; } if(x==40&&y>=20&&y<=60){ x=x-5; } if(x==80&&y<=80){ x=x-5; } } if(kood==KeyEvent.VK_LEFT){ x=x-5; if(x<=0&&y<=80){ x=x+5; } if(x==20&&y>=40&&y<=80){ x=x+5; } if(x==40&&y>=20&&y<=60){ x=x+5; } } if(kood==KeyEvent.VK_UP){ y=y-5; if(y==20&&x>=0&&x<=60){ y=y+5; } if(y==40&&x>=60&&x<=80){ y=y+5; } if(y==60&&x>=40&&x<=60){ y=y+5; } if(y==80&&x>=20&&y<=80){ y=y+5; } } if(kood==KeyEvent.VK_DOWN){ y=y+5; if(y==20&&x>=0&&x<=60){ y=y-5; } if(y==40&&x>=60&&x<=80){ y=y-5; } if(y==60&&x>=40&&x<=60){ y=y-5; } if(y==80&&x>=20&&y<=80){ y=y-5; } } if(y==85&&x>=0&&x<=20){ System.out.println("Finis!"); for(int y=85; x<100; x=x+5){ g=getGraphics(); g.setColor(Color.red); g.drawLine(x, y, x+5, y); x=x+5; try{Thread.sleep(100);}catch(Exception e){} } x=5; y=10; try{Thread.sleep(500);}catch(Exception e){} } repaint(); } public void keyReleased(KeyEvent k){} public void keyTyped(KeyEvent k){} public static void main(String argumendid[]){ Frame f=new Frame("Labürint"); f.add(new m2ng2()); f.setSize(300, 300); f.setVisible(true); } }