import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import org.apache.commons.lang.StringEscapeUtils;
public class lxim extends JApplet implements Runnable {
static final long serialVersionUID = 1;
public LXTextArea ausgabe;
public LXTextArea onliste;
public JTextField eingabe;
public JTextField neingabe;
public JTextField reingabe;
public JComboBox roomlist;
public JFrame frame;
public JViewport scrollaus, scrollonl;
public Socket sock;
public PrintStream out;
public InputStream in;
public BufferedReader br;
URL endurl;
public StringBuffer chat = new StringBuffer("<span style=\"color:white; font-family:Comic Sans MS; font-size:13pt;\">");
public StringBuffer liste = new StringBuffer();
public String input = new String();
public String vinput = new String();
public String hattergsagt = new String();
public String rooms[] = {
"Lobby",
"zocken",
"Idlers",
"Nerds",
"Verdammte",
"Sexy"
};
public int xx = 0, yy = 0;
public Component ein, rein, nein, aus, onl, rom;
Thread t = null;
public void start ()
{
t = new Thread(this);
t.start();
try {
endurl = new URL("http://www.djtraumwelt.de/lxim");
} catch (MalformedURLException e) {
}
while (t != null) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
getAppletContext().showDocument(endurl);
}
public void init ()
{
eingabe = new JTextField ();
ausgabe = new LXTextArea ("http://www.djtraumwelt.de/imgs/ausgabe.png");
onliste = new LXTextArea ("http://www.djtraumwelt.de/imgs/onliste.png");
roomlist = new JComboBox (rooms);
scrollaus = new JViewport();
scrollaus.setView(ausgabe);
scrollonl = new JViewport();
scrollonl.setView(onliste);
frame = new JFrame("LXIM");
frame.setSize(800, 500);
frame.setLayout( null );
ein = frame.getContentPane().add ( eingabe );
aus = frame.getContentPane().add ( scrollaus );
onl = frame.getContentPane().add ( scrollonl );
rom = frame.getContentPane().add ( roomlist );
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
t = null;
}
});
setsize();
Font font = new Font ("Serif", Font.PLAIN, 14);
ausgabe.setContentType("text/html");
//ausgabe.setFont (font);
onliste.setFont (font);
eingabe.setFont (font);
roomlist.setFont (font);
roomlist.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if ( e.getActionCommand() == "comboBoxChanged" ) {
rsenden();
}
}
});
//ausgabe.setForeground(Color.white);
onliste.setForeground(Color.white);
ausgabe.setEditable( false );
//ausgabe.setLineWrap( true );
//ausgabe.setWrapStyleWord(true);
onliste.setEditable( false );
ausgabe.setOpaque(false);
onliste.setOpaque(false);
eingabe.addActionListener(
new ActionListener () {
public void actionPerformed (ActionEvent ev) {
senden ();
}
}
);
}
public void run () {
verbinden ();
while ( t == Thread.currentThread() ) {
lesen ();
checksize();
try {
Thread.sleep(16);
} catch (InterruptedException e) {
t.interrupt();
}
}
try {
in.close();
out.close();
sock.close();
} catch (IOException e) {
}
}
public void checksize() {
if ( xx != frame.getWidth() || yy != frame.getHeight() ) {
xx = frame.getWidth();
yy = frame.getHeight();
if (frame.isVisible()) {
setsize();
}
}
}
public void setsize() {
int xxx = frame.getInsets().left;
xxx += frame.getInsets().right;
xxx = frame.getWidth() - xxx;
int yyy = frame.getInsets().top;
yyy += frame.getInsets().bottom;
yyy = frame.getHeight() - yyy;
ein.setBounds( 0, yyy-24, ( xxx*75 )/100, 24 );
aus.setBounds( 0, 0, ( xxx*75 )/100, yyy-24 );
onl.setBounds( ( xxx*75 )/100, 0, ( xxx*25 )/100, yyy-24 );
rom.setBounds( ( xxx*75 )/100, yyy-24, ( xxx*25 )/100, 24 );
ausgabe.setText( chat.toString() + "</span><br>");
onliste.setText ( liste.toString() );
roomlist.setVisible(false);
roomlist.setVisible(true);
}
public void stop () {
t = null;
}
public void verbinden () {
try {
sock = new Socket ("djtraumwelt.de", 6000);
sock.setTcpNoDelay(true);
out = new PrintStream (sock.getOutputStream(), true, "UTF-8" );
hattergsagt = "NAME " + getParameter("NAME") + "\0";
out.print (hattergsagt);
out.flush();
hattergsagt = "RAUM " + getParameter("RAUM") + "\0";
out.print (hattergsagt);
out.flush();
in = sock.getInputStream();
InputStreamReader inr = new InputStreamReader(in, "UTF-8");
br = new BufferedReader(inr);
} catch (UnknownHostException e) {
} catch (IOException e) {
}
}
public void senden () {
if (eingabe.getText().startsWith("/nick ")) {
nsenden();
eingabe.setText ("");
return;
}
hattergsagt = "SAY " + eingabe.getText() + "\0";
out.print (hattergsagt);
out.flush();
eingabe.setText ("");
}
public void nsenden () {
hattergsagt = "NAME " + eingabe.getText().substring(6) + "\0";
out.print (hattergsagt);
out.flush();
}
public void rsenden () {
hattergsagt = "RAUM " + rooms[roomlist.getSelectedIndex()] + "\0";
out.print (hattergsagt);
out.flush();
}
public void lesen () {
try {
if ( br.ready() ) {
input = br.readLine();
if ( input.startsWith("SAY ") ) {
vinput = StringEscapeUtils.escapeHtml( input.substring( 4 ) );
vinput = vinput.replaceAll(":\\)", "<img src=\"http://www.djtraumwelt.de/imgs/icon_smile.gif\">");
vinput = vinput.replaceAll("=\\)", "<img src=\"http://www.djtraumwelt.de/imgs/icon_smile.gif\">");
vinput = vinput.replaceAll(":\\(", "<img src=\"http://www.djtraumwelt.de/imgs/icon_nosmile.gif\">");
vinput = vinput.replaceAll("=\\(", "<img src=\"http://www.djtraumwelt.de/imgs/icon_nosmile.gif\">");
vinput = vinput.replaceAll(":D", "<img src=\"http://www.djtraumwelt.de/imgs/icon_biggrin.gif\">");
vinput = vinput.replaceAll("=D", "<img src=\"http://www.djtraumwelt.de/imgs/icon_biggrin.gif\">");
vinput = vinput.replaceAll(":P", "<img src=\"http://www.djtraumwelt.de/imgs/icon_baeh.gif\">");
vinput = vinput.replaceAll("=P", "<img src=\"http://www.djtraumwelt.de/imgs/icon_baeh.gif\">");
chat.append(vinput + "<br>");
ausgabe.setText( chat.toString() + "</span><br>");
ausgabe.setCaretPosition(ausgabe.getDocument().getLength());
}
if ( input.startsWith("LIST ") ) {
vinput = new String( input.substring( 5 ) );
liste = new StringBuffer();
liste.append( vinput );
liste.append( "\r\n" );
}
if ( input.startsWith("list ") ) {
vinput = new String( input.substring( 5 ) );
liste.append( vinput );
liste.append( "\r\n" );
}
if ( input.startsWith("ENDL") ) {
onliste.setText ( liste.toString() );
}
}
} catch (IOException e) {
}
}
}