Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.applet.Applet;
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- import java.net.*;
- public class lxim extends Applet implements Runnable {
- public TextField eingabe;
- public Label ausgabe;
- public Socket sock;
- public DataOutputStream out;
- public InputStream in;
- public BufferedReader br;
- public StringBuffer chat = new StringBuffer();
- public String input = new String();
- public String hattergsagt = new String();
- public char[] buffer = new char[1000];
- public void start ()
- {
- Thread t = new Thread(this);
- t.start();
- }
- public void init ()
- {
- verbinden ();
- eingabe = new TextField ("");
- ausgabe = new Label ();
- setLayout ( new BorderLayout() );
- add (BorderLayout.SOUTH, eingabe);
- add (BorderLayout.NORTH, ausgabe);
- eingabe.addActionListener(
- new ActionListener () {
- public void actionPerformed (ActionEvent ev) {
- senden ();
- }
- }
- );
- }
- public void run () {
- while (true) {
- lesen ();
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- }
- }
- }
- public void verbinden () {
- try {
- sock = new Socket ("djtraumwelt.de", 6000);
- out = new DataOutputStream (sock.getOutputStream() );
- //out.flush();
- in = sock.getInputStream();
- InputStreamReader inr = new InputStreamReader(in);
- br = new BufferedReader(inr);
- } catch (UnknownHostException e) {
- } catch (IOException e) {
- }
- }
- public void senden () {
- hattergsagt = "SAY " + eingabe.getText() + "\0";
- try {
- out.write (hattergsagt.getBytes());
- out.flush();
- } catch (IOException e) {
- }
- eingabe.setText ("");
- }
- public void lesen () {
- try {
- int i;
- if (br.ready() ) {
- i = br.read(buffer, 0, 1000);
- chat.append( buffer );
- ausgabe.setText (chat.toString() );
- }
- } catch (IOException e) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement