/** * tahvel java */ import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.util.*; public class tahvel extends Applet implements Runnable, MouseMotionListener{ BufferedReader sisse; PrintWriter valja; public tahvel(){ addMouseMotionListener(this); /** * Tekitame connectioni serverisse 193.40.238.77 */ try{ Socket sc=new Socket("193.40.238.77", 3001); sisse=new BufferedReader(new InputStreamReader(sc.getInputStream())); valja=new PrintWriter(sc.getOutputStream(), true); }catch(Exception e){} new Thread(this).start(); } /** * hiirega vedamise peale joone joonistamine */ public void mouseDragged(MouseEvent e){ Graphics g=getGraphics(); g.setColor(Color.black); //g.fillRect(e.getX(), e.getY(), 2, 2); valja.println(e.getX()+" "+e.getY()); } public void mouseMoved(MouseEvent e){} /** * selleks et teiste poolt joonistatu oleks näha */ public void run(){ while(true){ try{ Graphics g=getGraphics(); String rida=sisse.readLine(); StringTokenizer stk=new StringTokenizer(rida); int x=Integer.parseInt(stk.nextToken()); int y=Integer.parseInt(stk.nextToken()); g.fillRect(x, y, 2, 2); }catch(Exception e){} } } /** * akna enda joonistamiseks */ public static void main(String argumendid[]){ Frame f=new Frame("Joonistaja"); f.setSize(300, 300); f.add(new tahvel()); f.setVisible(true); } }