import java.applet.Applet; import java.awt.event.*; import java.awt.*; import java.net.*; import java.io.*; public class Vorguliiklus1 extends Applet implements KeyListener{ BufferedReader sisse; PrintWriter valja; String masin="localhost"; int port=3001; String nimi="Jaagup"; public Vorguliiklus1(){ try{ addKeyListener(this); Socket sc=new Socket(masin, port); valja=new PrintWriter(sc.getOutputStream(), true); sisse=new BufferedReader( new InputStreamReader(sc.getInputStream()) ); System.out.println(sisse.readLine()); valja.println(nimi); }catch(Exception viga){ viga.printStackTrace(); } } public void paint(Graphics g){ } public void keyPressed(KeyEvent e){ int kood=e.getKeyCode(); if(kood==KeyEvent.VK_LEFT){ valja.println(".vasakule"); } if(kood==KeyEvent.VK_RIGHT){ valja.println(".paremale"); } if(kood==KeyEvent.VK_UP){ valja.println(".yles"); } if(kood==KeyEvent.VK_DOWN){ valja.println(".alla"); } } public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} public static void main(String argumendid[]){ Frame f=new Frame("Klahvikuular"); f.add(new Vorguliiklus1()); f.setSize(300, 300); f.setVisible(true); } }