import java.awt.*; import java.net.*; import java.io.*; import java.awt.event.*; public class Kasutaja extends Frame implements Runnable, MouseListener, KeyListener { TextField tf=new TextField(50); Canvas louend=new Canvas(); int x, y, kood; String rida; PrintWriter valja; BufferedReader sisse; public Kasutaja(){ setTitle("Koordinaadid"); setLayout (new BorderLayout()); add (tf, BorderLayout.NORTH); add (louend, BorderLayout.CENTER); louend.addMouseListener(this); louend.addKeyListener(this); setSize(400, 300); setVisible(true); try{ Socket sc=new Socket("localhost", 3001); valja=new PrintWriter(sc.getOutputStream(), true); sisse=new BufferedReader(new InputStreamReader(sc.getInputStream())); new Thread(this).start(); }catch(IOException e){ System.out.println("Viga "+e); } } //---hiirekuularid---- public void mousePressed(MouseEvent e){ x=e.getX(); y=e.getY(); valja.println(x+" , "+y+"/n"); } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} //---klahvikuularid--- public void keyPressed(KeyEvent k){ int kood=k.getKeyCode(); if( kood==KeyEvent.VK_LEFT ){x=x-1;} if( kood==KeyEvent.VK_RIGHT ){x=x+1;} if( kood==KeyEvent.VK_UP ){y=y-1;} if( kood==KeyEvent.VK_DOWN ){y=y+1;} } public void keyReleased(KeyEvent k){} public void keyTyped(KeyEvent k){} //----------------- public void run(){ try{while(true){ String rida=sisse.readLine(); tf.setText(rida); } }catch(IOException pang){} } //----------------- public static void main(String argumendid[]){ new Kasutaja(); } }