import java.net.*; import java.io.*; import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class info extends Applet implements ActionListener, Runnable { TextField sisestus=new TextField(); TextArea sisu=new TextArea(10,1); Panel keskpaneel=new Panel(new GridLayout(1, 1)); Panel nupupaneel=new Panel(new GridLayout(4, 1)); Button nupp1=new Button("Küsi"); PrintWriter valja; BufferedReader sisse; Choice valik = new Choice(); public void init() { } public info() throws IOException{ setLayout(new BorderLayout()); add(nupp1, BorderLayout.NORTH); add(keskpaneel, BorderLayout.CENTER); add(nupupaneel, BorderLayout.SOUTH); nupp1.addActionListener(this); sisestus.addActionListener(this); valik.add("lin2.tpu.ee"); valik.add("madli.ut.ee"); valik.add("rasi.lr.ttu.ee"); valik.add("tera.hk.tpu.ee"); keskpaneel.add(sisu); nupupaneel.add(sisestus); nupupaneel.add(valik); nupupaneel.add(nupp1); } public void actionPerformed(ActionEvent e){ try{ if(e.getSource()==nupp1){ PrintWriter valjaf=new PrintWriter(new FileWriter("logi.txt",true)); sisu.setText(""); String snimi=valik.getSelectedItem(); System.out.println(snimi); //Socket sc=new Socket("lin2.tpu.ee", 79); Socket sc=new Socket(valik.getSelectedItem(), 79); BufferedReader sisse=new BufferedReader( new InputStreamReader(sc.getInputStream()) ); PrintWriter valja=new PrintWriter(sc.getOutputStream(), true); //valja.println("antsm"); valja.println(sisestus.getText()); String rida=sisse.readLine(); while(rida!=null){ //System.out.println(rida); sisu.append(rida+"\n"); //sisu.append(rida); System.out.println(rida); //sisu.insert(rida,10); rida=sisse.readLine(); } valjaf.println(valik.getSelectedItem()+" "+sisestus.getText()); valjaf.close(); } if(e.getSource()==sisestus){ } }catch(Exception ex){ex.printStackTrace();} } public void run(){ } public static void main(String[] argumendid) throws IOException{ Frame f=new Frame("Kasutaja info"); f.add(new info()); f.setSize(300, 300); f.setVisible(true); } }