import java.applet.*; import java.awt.*; import java.io.*; import java.net.*; import java.util.*; public class Koht01 extends Applet implements Runnable { private String serverName = "193.40.238.40"; private String chatChannel = "Default"; private int serverPort=3015; private String ise="1", sk="a"; private StringBuffer teised=new StringBuffer("xxxxx"); Socket socket; DataOutputStream outputs; DataInputStream inputs; Thread chatConnectionThread; Tah03 tahvel=new Tah03(200, 100); Label nimi=new Label("Mina"); TextArea t0, t1, t2, t3, t4; TextArea sisse; Button sendButton=new Button("Send"); Button pildinupp=new Button("Saada"); public void init() { t0=new TextArea(); add(t0); t0.hide(); t1=new TextArea(); add(t1); t1.hide(); t2=new TextArea(); add(t2); t2.hide(); t3=new TextArea(); add(t3); t3.hide(); t4=new TextArea(); add(t4); t4.hide(); sisse=new TextArea(); add(sisse); sisse.hide(); add(tahvel); tahvel.hide(); add(nimi); nimi.hide(); add(sendButton); sendButton.hide(); add(pildinupp);pildinupp.hide(); // t1.setEditable(false); t2.setEditable(false); t3.setEditable(false); t4.setEditable(false); t0.setEditable(false); chatConnectionThread = new Thread(this); chatConnectionThread.start(); } public void koik(){ t1.show(); t1.reshape(0, 0, 300, 100); t2.show(); t2.reshape(300, 0, 300, 100); t3.show(); t3.reshape(0, 100, 300, 100); t4.show(); t4.reshape(300, 100, 300, 100); nimi.show(); nimi.reshape(60, 230, 100, 50); sisse.show(); sisse.reshape(150, 200, 300, 100); sendButton.show(); sendButton.reshape(500, 235, 55, 30); t0.show(); t0.reshape(0, 300, 300, 150); tahvel.show(); tahvel.move(350, 320); pildinupp.show(); pildinupp.reshape(350, 420, 50, 15); } public boolean action(Event ev, Object ob) { if (ev.target.equals(sendButton)) { StringTokenizer message =new StringTokenizer(sisse.getText(), "\n"); while(message.hasMoreTokens()){ write("t"+ise+sk+"o"+message.nextToken());} sisse.setText(""); return true; } if (ev.target.equals(pildinupp)) { write("p"+ise+sk+"o"+tahvel.pildistring()); } return super.action(ev, ob); } public void seaise(String s){ this.ise=s; nimi.setText("Mina("+ise+")"); } public void run() { try { socket = new Socket(serverName,serverPort); outputs = new DataOutputStream(socket.getOutputStream()); inputs = new DataInputStream(socket.getInputStream()); String message; this.write("CHANNEL " + chatChannel); this.write("HISTORY"); koik(); boolean go = true; while (go) { message = inputs.readLine(); if ( message == null ) { go = false; } else { // t1.appendText(message+"\n"); if(message.charAt(0)=='k'){ if(message.substring(1, 3).compareTo("nr")==0){ seaise(message.substring(3, 4));} if(message.charAt(3)=='a'){koik();}} if(message.charAt(0)=='t'){ message=message+"\n"; if(message.charAt(1)=='0'){t0.appendText(message.substring(4));} if(message.charAt(1)=='1'){t1.appendText(message.substring(4));} if(message.charAt(1)=='2'){t2.appendText(message.substring(4));} if(message.charAt(1)=='3'){t3.appendText(message.substring(4));} if(message.charAt(1)=='4'){t4.appendText(message.substring(4));} } if(message.charAt(0)=='p'){tahvel.stringipilt(message.substring(4));} } } } catch (Exception e) { t1.appendText("CONNECTION ERROR :"+"\n"); t1.appendText(e.getMessage()+"\n"); } } void write( String mess ) { try { outputs.writeBytes(mess+"\n"); outputs.flush (); } catch (Exception e) { t1.appendText("OUTPUT ERROR :"+"\n"); t1.appendText(e.getMessage()+"\n"); } } }