Swing Version
This example applet is a close rewrite of the awt version, but implemented using Swing 1.2.2.
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TextCopySwing1 extends JApplet implements ActionListener{ JButton clear, display; JTextField input, output; JPanel buttonPanel; // hold two buttons public TextCopySwing1 ( ) { // constructor this.setFont ( new Font ( "Helvetica", Font.PLAIN, 18 ) ); display = new JButton ( "display" ); display.setBackground ( Color.red ); display.addActionListener ( this ); clear = new JButton ( "clear" ); clear.setBackground ( Color.green ); clear.addActionListener ( this ); input= new JTextField ("type message here", 30); output = new JTextField ("message display area", 30); output.setEditable ( false ); output.setBackground ( Color.yellow ); buttonPanel = new JPanel(); buttonPanel.setLayout ( new FlowLayout () ); buttonPanel.add ( display ); buttonPanel.add ( clear ); Container cp = this.getContentPane(); cp.setLayout ( new GridLayout ( 3, 1 ) ); cp.add ( buttonPanel ); cp.add ( input); cp.add ( output ); } // end MyPanelColorS constructor public void actionPerformed (ActionEvent e) { if ( e.getSource() == display ) { output.setText ( input.getText() ); return; } // end display if ( e.getSource() == clear ) { input.setText ( "" ); output.setText ( "" ); return; } // end display } // end action } // end TextCopy