import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; import javax.swing.Timer; public class JututoaKlient3 extends Applet implements ActionListener, MouseListener{ TextField tf=new TextField(); TextArea ta=new TextArea(); TextArea ta2=new TextArea(20, 10); JoonistusPaneel joonistuspaneel=new JoonistusPaneel(); Panel jaotuspaneel=new Panel(new GridLayout(2, 1)); BufferedReader sisse; PrintWriter valja; Timer t=new Timer(100, this); public JututoaKlient3(){ setLayout(new BorderLayout()); add(tf, BorderLayout.SOUTH); add(jaotuspaneel, BorderLayout.CENTER); jaotuspaneel.add(joonistuspaneel); joonistuspaneel.addMouseListener(this); joonistuspaneel.muudaAsukoht(".ring 50 30"); jaotuspaneel.add(ta); add(ta2, BorderLayout.EAST); tf.addActionListener(this); try{ Socket sc=new Socket("greeny.cs.tlu.ee", 3001); sisse=new BufferedReader(new InputStreamReader(sc.getInputStream())); valja=new PrintWriter(sc.getOutputStream(), true); t.start(); } catch(Exception ex){ ta.append(ex.getMessage()); } } public void mousePressed(MouseEvent e){ valja.println(".ring "+e.getX()+" "+e.getY()); } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void actionPerformed(ActionEvent e){ if(e.getSource()==tf){ valja.println(tf.getText()); tf.setText(""); } if(e.getSource()==t){ try{ if(sisse.ready()){ String rida=sisse.readLine(); if(rida.startsWith(".")){ if(rida.startsWith(".nimeloetelu")){ ta2.setText(""); rida=sisse.readLine(); while(!rida.startsWith(".nimeloeteluots")){ ta2.append(rida+"\n"); rida=sisse.readLine(); } } if(rida.startsWith(".ring")){ joonistuspaneel.muudaAsukoht(rida); } } else { ta.append(rida+"\n"); } } } catch(Exception ex){ ta.append(ex.getMessage()); } } } public static void main(String[] arg){ Frame f=new Frame("Klient"); f.setSize(500, 400); f.add(new JututoaKlient3()); f.setVisible(true); } }