Event Handling
in Applet
As we perform event handling in AWT or Swing, we can perform
it in
applet also.The simple example of event handling in applet that
prints a message by
click on the button.
Example of EventHandling in applet:
import java.applet.*; import java.awt.*; import java.awt.event.*;
public class EventApplet extends Applet implements ActionListener{
Button b;
TextField tf;
public void init(){
t f=new TextField();
t f.setBounds(30,40,150,20);
b=new Button("Click");
b.setBounds(80,150,60,50);
add(b);add(tf);
b.addActionListener(this);
setLayout(null);
}
public void actionPerformed(ActionEvent e){
tf.setText("Welcome");
}
myapplet.html
<html>
<body>
<applet code="EventApplet.class" width="300" height="300">
</applet>
</body>
</html>
Fig: Event Handling In Applet |
No comments:
Post a Comment