那位高手帮忙看看怎样将jtextField中的内容输出在jtextArea中显示!急急急
希望在jtextfield中按回车显示输出在jtextArea中,在这个代码基础上,谢谢啊!!importjava.awt.*;importjava.awt.event....
希望在jtextfield中按 回车 显示输出在jtextArea中,在这个代码基础上,谢谢啊!!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.*;
import javax.swing.text.JTextComponent;
public class Testtalk {
public static void main(String[] args) {
JFrame f=new JFrame("^聊天^");
f.setSize(400,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextField jtf=new JTextField(300);
/*JScrollPane jsp1=new JScrollPane(jtf);*/
f.add(jtf,"South");
JTextArea jta=new JTextArea();
JScrollPane jsp=new JScrollPane(jta);
f.add(jsp);
f.setVisible(true);
ActionListener l=new ActionListener(){
public void actionPerformed(ActionEvent arg0){
System.out.println("action!");
}
};
jtf.addActionListener(l);
}
} 展开
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.*;
import javax.swing.text.JTextComponent;
public class Testtalk {
public static void main(String[] args) {
JFrame f=new JFrame("^聊天^");
f.setSize(400,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextField jtf=new JTextField(300);
/*JScrollPane jsp1=new JScrollPane(jtf);*/
f.add(jtf,"South");
JTextArea jta=new JTextArea();
JScrollPane jsp=new JScrollPane(jta);
f.add(jsp);
f.setVisible(true);
ActionListener l=new ActionListener(){
public void actionPerformed(ActionEvent arg0){
System.out.println("action!");
}
};
jtf.addActionListener(l);
}
} 展开
展开全部
//这样就行了
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.*;
import javax.swing.text.JTextComponent;
public class Testtalk {
public static void main(String[] args) {
JFrame f = new JFrame("^聊天^");
f.setSize(400, 250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextField jtf = new JTextField(300);
/* JScrollPane jsp1=new JScrollPane(jtf); */
f.add(jtf, "South");
final JTextArea jta = new JTextArea();
final JScrollPane jsp = new JScrollPane(jta);
f.add(jsp);
f.setVisible(true);
ActionListener l = new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
jta.setText((jta.getText()+"\r\n"+jtf.getText()));
jtf.setText("");
}
};
jtf.addActionListener(l);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.*;
import javax.swing.text.JTextComponent;
public class Testtalk {
public static void main(String[] args) {
JFrame f = new JFrame("^聊天^");
f.setSize(400, 250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextField jtf = new JTextField(300);
/* JScrollPane jsp1=new JScrollPane(jtf); */
f.add(jtf, "South");
final JTextArea jta = new JTextArea();
final JScrollPane jsp = new JScrollPane(jta);
f.add(jsp);
f.setVisible(true);
ActionListener l = new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
jta.setText((jta.getText()+"\r\n"+jtf.getText()));
jtf.setText("");
}
};
jtf.addActionListener(l);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询