import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.net.*; import java.io.*; public class Klient1 extends Applet implements ActionListener, Runnable{ Button nupp=new Button("Ühenda"); TextField tf=new TextField(); TextArea ta=new TextArea(); PrintWriter valja; BufferedReader sisse; boolean sees=false; public Klient1(){ setLayout(new BorderLayout()); add(nupp, BorderLayout.NORTH); add(ta, BorderLayout.CENTER); add(tf, BorderLayout.SOUTH); nupp.addActionListener(this); tf.addActionListener(this); tf.setEnabled(false); } public void actionPerformed(ActionEvent e){ try{ if(e.getSource()==nupp){ if(sees){ valja.println(".ots"); } else { Socket sc=new Socket("ws0.cs1.tpu.ee", 3001); valja=new PrintWriter(sc.getOutputStream(), true); sisse=new BufferedReader(new InputStreamReader( sc.getInputStream())); tf.setEnabled(true); sees=true; nupp.setLabel("Lahku"); new Thread(this).start(); } } if(e.getSource()==tf){ valja.println(tf.getText()); tf.setText(""); } } catch(Exception ex){ex.printStackTrace();} } public void run(){ try{ for(String rida=sisse.readLine(); rida!=null; rida=sisse.readLine()){ ta.append(rida+"\n"); } }catch(Exception e){e.printStackTrace();} sees=false; nupp.setLabel("Ühenda"); } public static void main(String[] argumendid){ Frame f=new Frame("Jututoa graafiline klient"); f.add(new Klient1()); f.setSize(300, 300); f.setVisible(true); } }