急 。Java!!!!!!!!

在一个窗体内有两个文本框,要在一个中输入文字。要在另一个中显示出来,中间同过一个按钮。
求其关键语句~~~~~~~

主要就是按钮的响应,下面是一段可运行的代码:
关键就一行,在按钮事件里:this.jTextAreaReceive.setText(this.jTextAreaSend.getText());
下面是代码

public class NewJFrame extends javax.swing.JFrame {

public NewJFrame() {
initComponents();
this.setLocationRelativeTo(null);
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jScrollPane1 = new javax.swing.JScrollPane();
jTextAreaSend = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
jTextAreaReceive = new javax.swing.JTextArea();
jButtonSend = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jTextAreaSend.setColumns(20);
jTextAreaSend.setRows(5);
jScrollPane1.setViewportView(jTextAreaSend);

jTextAreaReceive.setColumns(20);
jTextAreaReceive.setRows(5);
jScrollPane2.setViewportView(jTextAreaReceive);

jButtonSend.setText("发送");
jButtonSend.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonSendActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 53, Short.MAX_VALUE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(147, Short.MAX_VALUE)
.addComponent(jButtonSend, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(137, 137, 137))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(34, 34, 34)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jButtonSend, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void jButtonSendActionPerformed(java.awt.event.ActionEvent evt) {
this.jTextAreaReceive.setText(this.jTextAreaSend.getText());
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton jButtonSend;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea jTextAreaReceive;
private javax.swing.JTextArea jTextAreaSend;
// End of variables declaration

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-12-02
做个监听~~~
第2个回答  2009-12-02
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String s=textfield1.getText();
textfield2.setText(s);}});
第3个回答  2009-12-02
import java.awt.*;
public class Text extends implements ActionListener{
TextField txt1=new TextField(15);
TextField txt2=new TextField(15);
Button btn=new Button("转换");
Text(){
super("txt窗口");
add(txt1);add(txt2);add(btn);
setVisible(true);
btn.addActionListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});

}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==btn){
txt2.setText(txt1.getText());
}
}
public static void main(String args []){
Text txt=new Text();
}
}
相似回答