import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.lang.*; import java.io.*; import java.net.*; import java.util.*; public class tahvel extends Applet implements MouseListener, MouseMotionListener{ int hax, hay; int hax2, hay2; int uusx, uusy; int uusx2, uusy2; Socket sc; Graphics2D piltg; //siit algab konstruktor public tahvel(){ addMouseListener(this); addMouseMotionListener(this); try{ sc=new Socket("teach1", 3001); new kuulaja(); } catch(Exception viga){ viga.printStackTrace(); } } public void mousePressed(MouseEvent e){ hax=e.getX(); hay=e.getY(); } public void mouseDragged(MouseEvent e){ uusx=e.getX(); uusy=e.getY(); try{ PrintWriter valja=new PrintWriter(sc.getOutputStream(), true); valja.println(hax+" "+hay+" "+uusx+" "+uusy); }catch(Exception viga){} hax=uusx; hay=uusy; } //kuulaja algab class kuulaja extends Thread{ public kuulaja(){ start(); } public void run(){ try{ BufferedReader sisse=new BufferedReader( new InputStreamReader(sc.getInputStream()) ); String lause=sisse.readLine(); while(lause!=null){ StringTokenizer tuhik=new StringTokenizer(lause, " "); String sona=tuhik.nextToken(); hax2=Integer.parseInt(sona); sona=tuhik.nextToken(); hay2=Integer.parseInt(sona); sona=tuhik.nextToken(); uusx2=Integer.parseInt(sona); sona=tuhik.nextToken(); uusy2=Integer.parseInt(sona); piltg=(Graphics2D)getGraphics(); piltg.setColor(Color.black); System.out.println(hax2+" "+hay2+" "+uusx2+" "+uusy2); piltg.drawLine(hax2, hay2, uusx2, uusy2); lause=sisse.readLine(); } }catch(Exception e){ e.printStackTrace(); } } } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseMoved(MouseEvent e){} public static void main(String argumendid[]){ Frame f=new Frame("tahvel"); f.setSize(600, 600); f.add(new tahvel()); f.setVisible(true); f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } } ); } }