import java.io.*; import java.net.*; import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class JututoaKlient extends Applet implements ActionListener, Runnable{ TextArea sisu=new TextArea(); TextField teade=new TextField(); BufferedReader vorgust; PrintWriter vorku; public JututoaKlient(){ setLayout(new BorderLayout()); add(sisu, BorderLayout.CENTER); add(teade, BorderLayout.SOUTH); teade.addActionListener(this); try{ Socket sc=new Socket("localhost", 3001); vorgust=new BufferedReader(new InputStreamReader(sc.getInputStream())); vorku=new PrintWriter(sc.getOutputStream(), true); new Thread(this).start(); } catch(IOException ex){ ex.printStackTrace(); } } public void actionPerformed(ActionEvent e){ vorku.println(teade.getText()); teade.setText(""); } public void run(){ try{ String rida=vorgust.readLine(); while(rida!=null){ sisu.append(rida+"\n"); rida=vorgust.readLine(); } }catch(Exception ex){ ex.printStackTrace(); } } public static void main(String[] arg){ Frame f=new Frame("Klient"); f.add(new JututoaKlient()); f.setSize(300, 300); f.setVisible(true); } }