运行后打字不能发送
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();
}
}