import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="layout.java" width=500 height=500>
</applet>
*/
public class layout extends Applet implements ActionListener
{
Button b1,b2,b3,b4,b5,b6,b7,b8;
public void init()
{
setLayout(new FlowLayout(FlowLayout.CENTER));
b1=new Button("red");
b2=new Button("cyan");
b3=new Button("pink");
b4=new Button("yellow");
b5=new Button("magenta");
b6=new Button("black");
b7=new Button("blue");
b8=new Button("orange");
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String s=ae.getActionCommand();
if(s.equals("red"))
setBackground(Color.red);
if(s.equals("cyan"))
setBackground(Color.cyan);
if(s.equals("pink"))
setBackground(Color.pink);
if(s.equals("yellow"))
setBackground(Color.yellow);
if(s.equals("magenta"))
setBackground(Color.magenta);
if(s.equals("black"))
setBackground(Color.black);
if(s.equals("blue"))
setBackground(Color.blue);
if(s.equals("orange"))
setBackground(Color.orange);
repaint();
}
}

No comments:
Post a Comment