public class ChatClient extends Frame{
TextField tf = new TextField(53);
TextArea ta = new TextArea();
Button bt = new Button("发送");
Panel p1 = new Panel();
Panel p2 = new Panel();
static int i = 0;
public class TextAreaExample {
public static void main(final String... args) {
EventQueue.invokeLater(new Runnable(){
@Override public void run() {
final JFrame frame = new JFrame("^_^");
final JTextArea history = new JTextArea();
final JTextField input = new JTextField();
frame.add(new JScrollPane(history), BorderLayout.CENTER);
frame.add(input, BorderLayout.PAGE_END);
final Action send = new AbstractAction("Send"){
@Override public void actionPerformed(final ActionEvent e){
String message = input.getText();
history.append(String.format("%s%n", message));
input.setText("");
}
};
input.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "SEND");
input.getActionMap().put("SEND", send);