import javax.swing.*; import java.awt.*; import java.awt.event.*; public class LabelCopy extends JPanel implements ActionListener { JLabel sourceLabel = new JLabel ("Origen"); JLabel targetLabel = new JLabel ("Destino"); JButton button = new JButton("Copiar"); LabelCopy () { setLayout(new GridLayout(3, 0)); add(sourceLabel); add(targetLabel); button.addActionListener (this); add(button); } public static void main(String[] args) { JFrame frame = new JFrame ("Ejercicio 2"); LabelCopy pane = new LabelCopy(); frame.getContentPane().add(pane, BorderLayout.CENTER); frame.addWindowListener (new WindowAdapter() { public void windowClosing (WindowEvent e) { System.exit(0); } } ); frame.pack(); frame.setVisible(true); } public void actionPerformed (ActionEvent e) { targetLabel.setText (sourceLabel.getText()); } }