import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.io.*; import java.net.*; public class JututoaKlient extends Applet implements ActionListener, Runnable{ TextArea ta=new TextArea(); TextField tf=new TextField(); BufferedReader sisse; PrintWriter valja; public JututoaKlient(){ setLayout(new BorderLayout()); add(ta, BorderLayout.CENTER); add(tf, BorderLayout.SOUTH); try{ Socket sc=new Socket("192.168.4.15", 3001); sisse=new BufferedReader(new InputStreamReader( sc.getInputStream() )); valja=new PrintWriter(sc.getOutputStream(), true); }catch(Exception e){e.printStackTrace();} tf.addActionListener(this); new Thread(this).start(); ta.setEditable(false); ta.setForeground(Color.red); ta.setFont(new Font("Times", Font.PLAIN, 20)); } public void run(){ try{ String rida=sisse.readLine(); while(rida!=null){ //ta.append(rida+"\n"); ta.setText(rida+"\n"+ta.getText()); rida=sisse.readLine(); } }catch(Exception e){e.printStackTrace();} } public void paint(Graphics g){ tf.requestFocus(); } public void actionPerformed(ActionEvent e){ valja.println(tf.getText()); tf.setText(""); } public static void main(String arg[]){ Frame f=new Frame("Jututoa klient"); f.add(new JututoaKlient()); f.setSize(300, 300); f.setVisible(true); } }