Wenn du eni bisschen Php kannst und nen Webserver hast kannst dus auch so machen (ist aber eine sehr ö uneffiziente Art
)
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.imageio.ImageIO;
import java.net.URL;
public class Chat extends Frame implements ActionListener{
String status = "Verbindung wird aufgebaut....", altbeitrag ="a",neubeitrag = "a", endtext="";
Image hintergrund, leiste;
URL quelle;
DataInputStream dis1;
boolean beginn = true;
int sleeptime = 3000;
TextField tf1;
TextArea ta1;
Button b1;
public Chat(){
this.setTitle("MOSIDA 0.2 (Messenger oder sowas in der Art)");
this.setBackground(new Color(220,220,220));
this.setBounds(20,20,600,500);
this.setVisible(true);
this.setLayout(null);
tf1 = new TextField();
tf1.setBounds(20,440,400,40);
tf1.setVisible(false);
tf1.setBackground(new Color(20,30,60));
tf1.setForeground(new Color(200,200,250));
this.add(tf1);
ta1 = new TextArea("",10,20,TextArea.SCROLLBARS_VERTICAL_ONLY );
ta1.setBounds(20,120,520,300);
ta1.setEditable(false);
ta1.setVisible(false);
ta1.setBackground(Color.WHITE);
ta1.setBackground(new Color(20,30,60));
ta1.setForeground(new Color(200,200,250));
ta1.setFont(new Font("TAHOMA",1,15));
this.add(ta1);
b1 = new Button("SENDEN");
b1.setBounds(440,440,120,40);
b1.setVisible(false);
this.add(b1);
b1.setBackground(new Color(20,30,60));
b1.setForeground(new Color(200,200,250));
b1.setFont(new Font("TAHOMA",1,15));
try{
leiste = ImageIO.read(new File("leiste.jpg"));
hintergrund = ImageIO.read(new File("hinten.jpg"));
}catch (Exception e){}
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
b1.addActionListener(this);
tf1.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e){
if(e.getKeyCode() == e.VK_ENTER){
sendit();
}
}
});
}
public static void main (String args[]){
Chat ch1 = new Chat();
ch1.lauf();
}
public void lauf(){
try{
quelle = new URL("hier würde ein phpskript stehen, der den letzten Post ausgibt
");
dis1 = new DataInputStream(quelle.openStream());
status = dis1.readLine();
Thread.sleep(500);
if (status != null){
this.repaint();
tf1.setVisible(true);
b1.setVisible(true);
ta1.setVisible(true);
}else {
status = "Connectierung schlug fehl!";
this.repaint();
}
while(1<2){
Thread.sleep(1000);
altbeitrag = neubeitrag;
quelle = new URL("");
dis1 = new DataInputStream(quelle.openStream());
neubeitrag = dis1.readLine();
if(!neubeitrag.equals(altbeitrag)){
endtext = ta1.getText();
endtext = endtext + "\n\n" + neubeitrag;
ta1.setText(endtext);
ta1.setCaretPosition(10000);
}
}
}catch(Exception ex){}
}
public void sendit(){
String neubeitrag1 = translateIt(tf1.getText());
try{
URL quelle2 = new URL("");
DataInputStream dis2 = new DataInputStream(quelle2.openStream());
tf1.setText("");
}catch(Exception e){}
}
public String translateIt(String text){
String helfer = "";
for(int x = 0; x < text.length(); x++){
if(text.substring(x,x+1).equals(" ")){
helfer= helfer + "%20";
}else{
helfer = helfer + text.substring(x,x+1);
}
}
return helfer;
}
public void paint(Graphics g){
if(hintergrund != null){
g.drawImage(hintergrund,0,0,Chat.this);
}
g.setColor(new Color(200,200,240));
if(leiste != null){
g.drawImage(leiste,20,50,Chat.this);
}else{
g.fillRect(20,50,560,50);
}
g.setFont(new Font("ARIAL", 1, 20));
g.setColor(Color.BLACK);
g.drawString(status,30,80);
}
public void actionPerformed(ActionEvent ae){
sendit();
}
}