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