import java.io.*; import java.awt.*; import java.net.*; import java.lang.*; import javax.swing.*; import java.awt.event.*; import java.util.Vector; import javax.swing.text.*; import java.util.StringTokenizer; import java.applet.*; public class klient extends Applet implements ActionListener,Runnable{ String host="ws25"; int port=113; Button b1=new Button("Ühenda"); TextArea ta1=new TextArea(); TextField tf1=new TextField("Aadu"); Panel p=new Panel(new GridLayout(1,2)); PrintWriter pw1; public klient(){ p.add(b1); p.add(tf1); b1.addActionListener(this); tf1.addActionListener(this); setLayout(new BorderLayout()); add(ta1,BorderLayout.CENTER); add(p,BorderLayout.SOUTH); } public static void main(String a[]){ Frame f=new Frame("..."); f.add(new klient()); f.setSize(300,300); f.setVisible(true); } public void actionPerformed(ActionEvent e){ if(e.getSource()==b1){ new Thread(this).start(); } if(e.getSource()==tf1){ pw1.println(tf1.getText()); System.out.println("aaa"); } } public void run(){ try{ Socket sc=new Socket(host,port); pw1=new PrintWriter(sc.getOutputStream(), true); BufferedReader br1=new BufferedReader(new InputStreamReader(sc.getInputStream())); System.out.println("Serveriga uhendus loodud - "+host+":"+port); while(true){ System.out.println("1"); String rida=br1.readLine(); if(rida.startsWith("nimi")){ pw1.println(tf1.getText()); System.out.println("saatsin"); } if(rida.startsWith(".nimekiri")){ System.out.println("1"); pakilahti(rida); } //ta1.append(rida+"\n"); } }catch(Exception e){ System.out.println("jama"+e); } } public void pakilahti(String a){ //.nimekiri[Aadu, karud, Aadu, rebased] ta1.setText("nimi-võistkond\n"); ta1.append("-------------------\n"); String rida=a.substring(10); System.out.println(rida); StringTokenizer st=new StringTokenizer(rida,","); ta1.append(st.nextToken()+" - "+st.nextToken()+"\n"); while(st.hasMoreTokens()){ ta1.append(st.nextToken().substring(1)+" - "+st.nextToken()+"\n"); } ta1.append("-------------------\n"); } }