import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class ColorApplet extends Applet implements ActionListener
{
Button b1,b2,b3;
public void init()
{
b1 = new Button("Red");
b2 = new Button("Green");
b3 = new Button("Blue");
add(b1);add(b2);add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
setBackground(Color.yellow);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
setBackground(Color.red);
if(ae.getSource()==b2)
setBackground(Color.green);
if(ae.getSource()==b3)
setBackground(Color.blue);
}
}
/*<applet code=ColorApplet height=300 width=300></applet>*/
import java.awt.event.*;
import java.applet.*;
public class ColorApplet extends Applet implements ActionListener
{
Button b1,b2,b3;
public void init()
{
b1 = new Button("Red");
b2 = new Button("Green");
b3 = new Button("Blue");
add(b1);add(b2);add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
setBackground(Color.yellow);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
setBackground(Color.red);
if(ae.getSource()==b2)
setBackground(Color.green);
if(ae.getSource()==b3)
setBackground(Color.blue);
}
}
/*<applet code=ColorApplet height=300 width=300></applet>*/
No comments:
Post a Comment