Design a GUI application as shown below and perform the foll
Design a GUI application as shown below and perform the following tasks when each button is clicked:
Copy: Copy the content from the left side textarea to the right textarea
Append: Append the content on the left side textarea to the end of the right side textarea.
Solution
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Task1 {
public static void main(String[] args)
{
JFrame f=new JFrame();//creating instance of JFrame
f.setSize(800,300);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
JPanel p = new JPanel();
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
f.add(p);
final JTextArea textArea0 = new JTextArea(\"JTextArea0\",15,22);
final JTextArea textArea1 = new JTextArea(\"JTextArea1\",15,22);
final JButton copyButton = new JButton(\"Copy\");//creating instance of JButton
final JButton appendButton = new JButton(\"Append\");
final JButton clearButton = new JButton(\"Clear\");
copyButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textArea1.setText(textArea0.getText());
}
});
appendButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textArea1.setText(textArea1.getText() + textArea0.getText());
}
});
clearButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textArea1.setText(\" \");
}
});
JButton b=new JButton(\"click\");
p.add(p1);
p1.add(textArea0);
p.add(p2);
p2.add(copyButton);
p2.add(appendButton);
p2.add(clearButton);
p.add(p3);
p3.add(textArea1);
p1.setSize(200,200);
p2.setSize(50,50);
p3.setSize(200,200);
p.setSize(500,200);
p2.setLayout(new GridLayout(3,1));
p.setLayout(new GridLayout(1,3));
f.setVisible(true);//making the frame visible
}
}

