………………………………………………………………………………………….
Save this file as=> ex.java
………………………………………………………………………………………..
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class ex extends Applet implements ActionListener
{
Button
b1,b2;
{
b1=new
Button("RED");
add(b1);
b1.addActionListener(this);
b2=new
Button("GREEN");
add(b2);
b2.addActionListener(this);
}
public void
actionPerformed(ActionEvent e1)
{
if(e1.getSource()==b1)
{
setBackground(Color.red);
}
if(e1.getSource()==b2)
{
setBackground(Color.green);
}
}
}
…………………………………………………………………………………………
compile this file: javac ex.java
………………………………………………………………………………………..
HTML file ex.html
<applet code ="ex.class"
width=200
height=200>
</applet>
Output:
No comments:
Post a Comment