Event Handling using Anonymous Class in Applet

We can handle the Event in Applet, AWT or Swing by following three different methods:

  • Inner Class
  • Anonymous class
  • this Pointer

In this example, i will show you that how to use Anonymous classes to handle the events in Applet.

package com.kunal.applet;

import java.applet.Applet;
import java.awt.Button;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AnonymouseButton extends Applet {

  TextField txtSource;
  Button btnToLOwer;

  public void init()
  {
     txtSource=new TextField(20);
     btnToLOwer=new Button("Lower Case");
     btnToLOwer.addActionListener(new ActionListener(){

       @Override
       public void actionPerformed(ActionEvent e) {

       String tmp=txtSource.getText();
       tmp=tmp.toLowerCase();
       txtSource.setText(tmp);

     }});

    add(txtSource);
    add(btnToLOwer);
  }
 }

Event Handling using Anonymous Class in Applet

Posted

in

by


Related Posts

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading