import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; public class GrKlient1a extends Applet implements ActionListener, Runnable{ TextArea tf1=new TextArea(5, 50); //suurus TextField tfKasutajanimi=new TextField("Kasutajanimi"); Button nupp1=new Button("Ühenda"); Button sisesta=new Button("Sisesta"); TextArea ta1=new TextArea(5, 20); Panel p1=new Panel(new BorderLayout()); //2 rida ja 1 veerg tabelis Label silt1=new Label(); PrintWriter pw1; BufferedReader br1; String seisund="algus"; public GrKlient1a(){ setLayout(new BorderLayout()); p1.add(tf1, BorderLayout.NORTH); p1.add(sisesta, BorderLayout.SOUTH); add(p1, BorderLayout.SOUTH); // add(nupp1, BorderLayout.NORTH); add(tfKasutajanimi, BorderLayout.NORTH); add(ta1, BorderLayout.CENTER); // tf1.addActionListener(this); nupp1.addActionListener(this); sisesta.addActionListener(this); } public void actionPerformed(ActionEvent e){ if(e.getSource()==sisesta){ if(tf1.getText().length()==0){return;} pw1.println(tfKasutajanimi.getText()+": "+tf1.getText()); tf1.setText(""); /* if(seisund.equals("nimesisestus")){ silt1.setText("Palun parool"); tf1.setEchoChar('*'); seisund="paroolisisestus"; } */ } if(e.getSource()==nupp1){ try{ }catch(Exception viga){ ta1.setText(viga.getMessage()); } } } public void start(){ try{ Socket sc=new Socket("minitorn.tlu.ee", 3001); pw1=new PrintWriter(sc.getOutputStream(), true); br1=new BufferedReader(new InputStreamReader(sc.getInputStream())); new Thread(this).start(); silt1.setText("Palun nimi: "); seisund="nimesisestus"; }catch(Exception viga){ ta1.setText(viga.getMessage()); } } public void run(){ try{ String rida=br1.readLine(); while(rida!=null){ ta1.append(rida+"\n"); rida=br1.readLine(); } }catch(Exception viga){ viga.printStackTrace(); ta1.append("Oled väljas"); } seisund="algus"; } public static void main(String[] argumendid){ Frame f=new Frame(); f.add(new GrKlient1a()); f.setSize(300, 300); f.setVisible(true); f.addWindowListener(new Raamikuular()); } static class Raamikuular extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.out.println("Programmi ots"); System.exit(0); } } }