import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

 public class Applet extends JApplet {
    
      private ActionListener bli = new ActionListener() {
   public void actionPerformed(ActionEvent e) {
     String name = ((JButton)e.getSource()).getText();
     txt.setText(name);
   }
 };
 private JButton
     button = new JButton("Button"),
   private JTextField txt = new JTextField(10);
 public void init() {
    button.addActionListener(bli);
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(button);
    cp.add(txt);
 }

 public static void main(String[] args){
   JApplet applet = new Applet();
    JFrame frame = new JFrame("Applet");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(applet);
   frame.setSize(200,200);
        applet.init();
     applet.start();
    frame.setVisible(true);

       }

   }

 /*<applet code=AnApplet.class width=200 height=200>
</applet>
*/