import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.util.*; public class Jutugrklient3 extends Applet implements Runnable, MouseListener{ BufferedReader sisse; PrintWriter valja; HashMap kasutajad=new HashMap(); public Jutugrklient3(){ try{ Socket sc=new Socket("ws0.cs1.tpu.ee", 3001); sisse=new BufferedReader(new InputStreamReader(sc.getInputStream())); valja=new PrintWriter(sc.getOutputStream(), true); addMouseListener(this); }catch(Exception e){} new Thread(this).start(); } public void mousePressed(MouseEvent e){ valja.println("jaagup "+e.getX()+" "+e.getY()); } public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void run(){ while(true){ try{ String rida=sisse.readLine(); StringTokenizer stk=new StringTokenizer(rida); String kasutajanimi=stk.nextToken(); int x=Integer.parseInt(stk.nextToken()); int y=Integer.parseInt(stk.nextToken()); Punkt p=new Punkt(); p.x=x; p.y=y; kasutajad.put(kasutajanimi, p); repaint(); }catch(Exception e){} } } public void paint(Graphics g){ Iterator loend=kasutajad.keySet().iterator(); while(loend.hasNext()){ String nimi=(String)loend.next(); Punkt p=(Punkt)kasutajad.get(nimi); g.drawString(nimi, p.x, p.y); } } public static void main(String argumendid[]){ Frame f=new Frame("Graafiline jututuba"); f.setSize(300, 300); f.add(new Jutugrklient3()); f.setVisible(true); } class Punkt{ int x, y; } }