java中如何将单行文本域中的内容写到文本区中

将单行文本域中的内容写到文本区中... 将单行文本域中的内容写到文本区中 展开
 我来答
godwin668
2010-06-03 · TA获得超过367个赞
知道小有建树答主
回答量:135
采纳率:0%
帮助的人:179万
展开全部

你是要将文本域中的内容添加到文本区的后面吧?

*****************************************************************

 新建类TextTrans.java,代码如下:

*****************************************************************

import java.awt.BorderLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JTextArea;

import javax.swing.JTextField;

public class TextTrans extends JFrame {

 JTextField tf;

 JTextArea ta;

 JButton b;

 public TextTrans() {

  tf = new JTextField(20);

  ta = new JTextArea(5, 20);

  b = new JButton(" 确定 ");

  this.add(tf, BorderLayout.NORTH);

  this.add(ta, BorderLayout.CENTER);

  this.add(b, BorderLayout.SOUTH);

  this.pack();

  this.setVisible(true);

  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  b.addActionListener(new ActionListener() {

   public void actionPerformed(ActionEvent e) {

    ta.append(tf.getText() + "\n");

   }

  });

 }

 public static void main(String[] args) {

  new TextTrans();

 }

}

*****************************************************************

 运行结果如下:

*****************************************************************

mzocean
2010-06-04 · TA获得超过1083个赞
知道小有建树答主
回答量:492
采纳率:33%
帮助的人:461万
展开全部

import java.awt.*;

import java.awt.event.*;

class TestCopy implements ActionListener{

 Frame f;

 TextField tf=new TextField(30);

 Button b=new Button("确定");

 TextArea ta=new TextArea("",10,20,TextArea.SCROLLBARS_VERTICAL_ONLY);

 Panel p=new Panel(new FlowLayout(FlowLayout.CENTER));

 TestCopy(String s){

  f=new Frame(s);

  b.addActionListener(this);

  tf.addActionListener(this);//按回车也可以

  p.add(tf);p.add(b);

  f.setLayout(new BorderLayout());

  f.add(p,BorderLayout.NORTH);

  f.add(ta,BorderLayout.CENTER);

  f.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e1){

 System.exit(0);

}

});

  f.setLocation(300,200);

  f.setSize(300,200);

  f.setVisible(true);

 }

 public void actionPerformed(ActionEvent e){

  if(e.getSource()==b||e.getSource()==tf){

   ta.append(tf.getText()+"\n");

   tf.setText("");//将TextField置空,不需要就去掉

  }

 }

 public static void main (String[] args) {

  new TestCopy("标题照片挡住了");

}

}

图:

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式