import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class colorbutt extends Applet
{
Label l;
TextField tf;
Button b1,b2;
public void init()
{
b1 = new Button("Color");
b2 = new Button("No Color");
add(b1); add(b2);
b1.addActionListener(new s());
b2.addActionListener(new s());
}
class s implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
setBackground(Color.red);
}
if(e.getSource()==b2)
{
setBackground(Color.white);
}
}
}
}
/* <applet code = "colorbutt.class" height = 300 width = 300>
</applet> */Java
Java Applet - Change Background Color using Button

Written by
View ProfileSenthilvelan Sambamoorthy
Senthilvelan Sambamoorthy is working as a Professor in Department of Master of Computer Applications, Paavai Engineering College, Namakkal, Tamilnadu, India, He is Masters in Computers Applications. Having 18+ years of experience and his area of interest is Java, JSP, Servlet, J2EE, C#, PHP, Python ASP.NET, SQL Server and etc.
