Here's a simple example of how event handling can be implemented in an applet
import java.awt.event.*; import java.applet.*; import java.awt.*; public class MyApplet extends Applet implements ActionListener { Button b; public void init() { b = new Button("Click Me"); b.addActionListener(this); add(b); } public void actionPerformed(ActionEvent ae) { b.setLabel("You clicked me"); } }
In this example, the MyApplet
class extends the Applet
class and implements the ActionListener
interface. The init
method creates a button, adds it to the applet, and sets itself as the action listener for the button. The actionPerformed
method is called whenever the button is clicked and updates the label on the button to indicate that it has been clicked.
The basic principle is the same when handling events in an applet, which is to react to user interactions with the applet's GUI components. Other approaches include using anonymous inner classes or implementing various listener interfaces.
Police Colony
Patna, Bihar
India
Email:
Post your comment