Java

Java Applet - Color Palette Program

Java Applet - Color Palette Program
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class colorpala extends Applet
{
Button b1,b2,b3,b4,b5,b6,b7,b8,b9;
TextArea ta;
CheckboxGroup cg;
Checkbox r1,r2;

public void init()
{
setLayout(new FlowLayout());

ta = new TextArea(10,50);

cg = new CheckboxGroup();

r1 = new Checkbox("BackGround",cg,false);
r2 = new Checkbox("ForeGround",cg,false);

b1 = new Button("red");
b2 = new Button("blue");
b3 = new Button("yellow");
b4 = new Button("black");
b5 = new Button("cyan");
b6 = new Button("green");
b7 = new Button("orange");

add(ta); add(r1); add(r2);
add(b1); add(b2); add(b3);
add(b4); add(b5); add(b6);
add(b7);

b1.addActionListener(new a());
b2.addActionListener(new a());
b3.addActionListener(new a());
b4.addActionListener(new a());
b5.addActionListener(new a());
b6.addActionListener(new a());
b7.addActionListener(new a());

}

class a implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
if(r1.getState()==true)
{
ta.setBackground(Color.red);
}
else 
{
ta.setForeground(Color.red);
}
}

if(e.getSource()==b2)
{
if(r1.getState()==true)
{
ta.setBackground(Color.blue);
}
else 
{
ta.setForeground(Color.blue);
}
}

if(e.getSource()==b3)
{
if(r1.getState()==true)
{
ta.setBackground(Color.yellow);
}
else 
{
ta.setForeground(Color.yellow);
}
}

if(e.getSource()==b4)
{
if(r1.getState()==true)
{
ta.setBackground(Color.black);
}
else 
{
ta.setForeground(Color.black);
}
}

if(e.getSource()==b5)
{
if(r1.getState()==true)
{
ta.setBackground(Color.cyan);
}
else 
{
ta.setForeground(Color.cyan);
}
}

if(e.getSource()==b6)
{
if(r1.getState()==true)
{
ta.setBackground(Color.orange);
}
else 
{
ta.setForeground(Color.orange);
}
}

if(e.getSource()==b7)
{
if(r1.getState()==true)
{
ta.setBackground(Color.green);
}
else 
{
ta.setForeground(Color.green);
}
}


}
}
}


/* <body>
<applet code = "colorpala.class" height = 350 width = 600>
</applet>
</body> */
Senthilvelan 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.