G
Guest
Gast
Hallo, habe in meinem Chatprogramm, welches ich hier letztens gefunden hab natürlich einen ActionEveetn mit drinnen.
Wenn ich allerdings auf ENTER klicke passiert nicht. Kann mir jemand sagen woran das liegt.
Wenn ich allerdings auf ENTER klicke passiert nicht. Kann mir jemand sagen woran das liegt.
Code:
import java.net.*;
import java.io.*;
import java.awt.*;
import java.applet.*;
public class chatapplet extends Applet implements Runnable
{
public Frame f;
public static final int PORT = 63631;
Socket socket;
DataInputStream in ;
PrintStream out;
TextField inputfield;
TextArea outputarea;
Choice choiceChannel;
List users;
Thread thread;
public void init()
{
f = new Frame("Agent159's knuddeliger Chat");
f.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
f.dispose();
} });
inputfield = new TextField();
outputarea = new TextArea();
users = new List();
outputarea.setFont( new Font("Dialog", Font.PLAIN, 12));
outputarea.setEditable(false);
f.add(inputfield);
f.add(outputarea);
f.add(users);
f.setLayout(new BorderLayout());
f.add("South", inputfield);
f.add("Center", outputarea);
f.add("East", users);
f.setBackground(Color.lightGray);
f.setForeground(Color.white);
inputfield.setBackground(Color.darkGray);
outputarea.setBackground(Color.darkGray);
users.setBackground(Color.darkGray);
f.pack();
f.setSize(500,300);
f.show();
}
public void start()
{
try
{
socket = new Socket(InetAddress.getByName("isis1.cs.uni-magdeburg.de"),PORT);
in = new DataInputStream(socket.getInputStream());
out = new PrintStream(socket.getOutputStream());
say("Verbindung zum Server aufgenommen...");
} catch (IOException e)
{
this.showStatus(e.toString());
say("Verbindung zum Server fehlgeschlagen!");
//System.exit(1);
}
if (thread == null)
{
thread = new Thread(this);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
}
public void stop()
{
try
{
socket.close();
} catch (IOException e)
{
this.showStatus(e.toString());
}
if ((thread !=null) && thread.isAlive())
{
thread.stop();
thread = null;
}
}
public void run()
{
String line;
try
{
while(true)
{
line = in.readLine();
if(line!=null)
outputarea.appendText(line+'\n' );
}
} catch (IOException e) { say("Verbindung zum Server abgebrochen"); }
}
public boolean action(Event e, Object what)
{
if (e.target==inputfield)
{
String inp=(String) e.arg;
out.println(inp);
inputfield.setText("");
return true;
}
return false;
}
public void say(String msg)
{
outputarea.appendText("*** "+msg+" ***\n");
}
}