62,614
社区成员
发帖
与我相关
我的任务
分享
import java.awt.*;
import java.awt.event.*;
public class ChatClient extends Frame {
TextField tfTxt = new TextField();
TextArea taContent = new TextArea();
public static void main(String[] args) {
new ChatClient().launchFrame();
}
public void launchFrame() {
setLocation(400, 300);
this.setSize(300, 300);
add(tfTxt, BorderLayout.SOUTH);
add(taContent, BorderLayout.NORTH);
pack();
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}
});
tfTxt.addActionListener(new TFListener());
setVisible(true);
}
private class TFListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String s = tfTxt.getText().trim();
taContent.setText(s);
tfTxt.setText("");
}
}
}