Question

Using Netbeans •Create a GUI consisting of two JTextFields and two JButtons. –When the first button...

Using Netbeans

•Create a GUI consisting of two JTextFields and two JButtons.

–When the first button is clicked, the contents of the first textfield is copied to the second textfield.

–When the second button is clicked, both textfields are cleared.

•Remember, the Javadocs are your friends.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:::

CopyData.java

package graphichal;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class CopyData{
   CopyData(){
       final JFrame f=new JFrame(); //we are using jframe
       f.setPreferredSize(new Dimension(800,300));
       f.setLayout(null);
       final JButton copy=new JButton("Copy");
       copy.setBounds(0, 50, 270,30);
       f.add(copy);
      
       final JButton clear=new JButton("Clear");
       clear.setBounds(400, 50, 270,30);
       f.add(clear);
      
       final JTextField field1=new JTextField("");
       field1.setBounds(0, 0, 270,30);
       f.add(field1);
      
       final JTextField field2=new JTextField("");
       field2.setBounds(400, 0, 270,30);
       f.add(field2);

       copy.addActionListener(new ActionListener() {
          
           @Override
           public void actionPerformed(ActionEvent arg0) {
               field2.setText(field1.getText());
           }
       });
      
       clear.addActionListener(new ActionListener() {
          
           @Override
           public void actionPerformed(ActionEvent arg0) {
               field2.setText("");
               field1.setText("");
           }
       });

       f.pack();
       f.setVisible(true);
   }


   public static void main(String[] args){
       CopyData f = new CopyData();

   }
}

output:

Add a comment
Know the answer?
Add Answer to:
Using Netbeans •Create a GUI consisting of two JTextFields and two JButtons. –When the first button...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT