GUI Programming note 07:gui Moving the value of a text box to a text field case

Source: Internet
Author: User

1. First we look at our needs, as follows:

Enter "Wind", click "Data Transfer", such text will appear in the following text field, this is our needs.

2. The code is as follows:

 Packagecn.itcast_05;ImportJava.awt.Button;Importjava.awt.FlowLayout;ImportJava.awt.Frame;ImportJava.awt.TextArea;ImportJava.awt.TextField;Importjava.awt.event.ActionEvent;ImportJava.awt.event.ActionListener;ImportJava.awt.event.WindowAdapter;Importjava.awt.event.WindowEvent; Public classFramedemo { Public Static voidMain (string[] args) {//Create a Form objectFrame f =NewFrame ("Data transfer"); //set form properties and layoutsF.setbounds (400, 200, 400, 300); F.setlayout (NewFlowLayout ()); //Create a text box        FinalTextField tf =NewTextField (20); //Create buttonButton bu =Newbutton ("Data transfer"); //Create a text field        FinalTextArea TA =NewTextArea (10, 40); //Add components to a formF.add (TF);        F.add (BU);        F.add (TA); //set the form to closeF.addwindowlistener (NewWindowadapter () {@Override Public voidwindowclosing (windowevent e) {system.exit (0);        }        }); //add an event to a buttonBu.addactionlistener (NewActionListener () {@Override Public voidactionperformed (ActionEvent e) {//get the value of a text boxString Tf_str =tf.gettext (). Trim (); //Clear DataTf.settext (""); //set to Text field//Ta.settext (TF_STR); //Append and line wrappingTa.append (tf_str + "\ r \ n"); //Get cursorTf.requestfocus ();        }        }); //set the form displayF.setvisible (true); }}

The results of the operation are as follows:

GUI Programming note 07:gui Moving the value of a text box to a text field case

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.