日期:2014-05-20  浏览次数:20803 次

运行后打字不能发送
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class ChatClient {
public static void main(String[] args) {
new JieMian().launghFrame();
}
}

class JieMian extends Frame {
TextField tFile = new TextField();
TextArea tArea = new TextArea();

public void launghFrame() {
setBounds(200, 300, 300, 400);
add(tFile, BorderLayout.SOUTH);
add(tArea, BorderLayout.CENTER);
tFile.addActionListener(new FaSong());
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setVisible(true);
}

private class FaSong implements ActionListener {

public void actionPerformed(ActionEvent e) {
String s = tFile.getText().trim();
tArea.setText(s);
tArea.setText("");

}

}
}

------解决方案--------------------
tArea.setText("");把结果覆盖掉了
------解决方案--------------------


private class FaSong implements ActionListener {
public void actionPerformed(ActionEvent e) {
String s=tFile.getText().trim();
tArea.setText(tArea.getText()+"\n"+s);
}
}

------解决方案--------------------

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class ChatClient {
public static void main(String[] args) {
new JieMian().launghFrame();
}
}

class JieMian extends Frame {
TextField tFile = new TextField();
TextArea tArea = new TextArea();

public void launghFrame() {
setBounds(200, 300, 300, 400);
add(tFile, BorderLayout.SOUTH);
add(tArea, BorderLayout.CENTER);
tFile.addActionListener(new FaSong());
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setVisible(true);
}

private class FaSong implements ActionListener {

public void actionPerformed(ActionEvent e) {
String s = tFile.getText().trim();
tArea.setText(tArea.getText() + "\n" + s);
tFile.setText("");

}

}
}

------解决方案--------------------
这里改一下吧。
	private class FaSong implements ActionListener
{

public void actionPerformed(ActionEvent e)
{
String s = tFile.getText().trim();
tArea.setText(s);
tFile.setText("");
tArea.repaint();
}

}