Important alert: (current site time 4/16/2014 8:46:30 PM EDT)
 

VB icon

Color Palette

Email
Submitted on: 5/29/2012 8:25:28 AM
By: Rekha Ram Chaudhary  
Level: Intermediate
User Rating: Unrated
Compatibility: Java (JDK 1.5)
Views: 1813
author picture
(About the author)
 
     Create a color palette with matrix of buttons Set background and foreground of the control text area by selecting a color from color palette. In order to select Foreground or background use check box control as radio buttons.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Color Palette
// Description:Create a color palette with matrix of buttons Set background and foreground of the control text area by selecting a color from color palette. In order to select Foreground or background use check box control as radio buttons.
// By: Rekha Ram Chaudhary
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=7030&lngWId=2//for details.//**************************************

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=color.class width=300 height=300>
</applet>*/
public class color extends Applet implements ActionListener,ItemListener
{
int f=0;
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12;
TextField name;
Checkbox fore,back;
CheckboxGroup cbg;
public void init()
{
setBackground(Color.cyan);
setForeground(Color.red);
b1=new Button("green");
b2=new Button("red");
b3=new Button("yellow");
b4=new Button("orange");
b5=new Button("pink");
b6=new Button("magenta");
b7=new Button("white");
b8=new Button("cyan");
b9=new Button("black");
b10=new Button("blue");
b11=new Button("gray");
b12=new Button("lightgray");
cbg=new CheckboxGroup();
back=new Checkbox("Background",cbg,false);
fore=new Checkbox("Foreground",cbg,true);
Label namep=new Label("Name :",Label.RIGHT);
name=new TextField("Hello World!!");
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
add(b10);
add(b11);
add(b12);
add(namep);
add(name);
add(back);
add(fore);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
name.addActionListener(this);
back.addItemListener(this);
fore.addItemListener(this);
}
public void paint(Graphics g)
{ repaint();
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if(f==1)
{ if(str.equals("green"))
name.setBackground(Color.green);
else
if(str.equals("red"))
name.setBackground(Color.red);
else
if(str.equals("yellow"))
name.setBackground(Color.yellow);
else
if(str.equals("orange"))
name.setBackground(Color.orange);
else
if(str.equals("pink"))
name.setBackground(Color.pink);
else
if(str.equals("magenta"))
name.setBackground(Color.magenta);
else
if(str.equals("white"))
name.setBackground(Color.white);
else
if(str.equals("cyan"))
name.setBackground(Color.cyan);
else
if(str.equals("black"))
name.setBackground(Color.black);
else
if(str.equals("blue"))
name.setBackground(Color.blue);
else
if(str.equals("gray"))
name.setBackground(Color.gray);
else
name.setBackground(Color.lightGray);
}
else
{ if(str.equals("green"))
name.setForeground(Color.green);
else
if(str.equals("red"))
name.setForeground(Color.red);
else
if(str.equals("yellow"))
name.setForeground(Color.yellow);
else
if(str.equals("orange"))
name.setForeground(Color.orange);
else
if(str.equals("pink"))
name.setForeground(Color.pink);
else
if(str.equals("magenta"))
name.setForeground(Color.magenta);
else
if(str.equals("white"))
name.setForeground(Color.white);
else
if(str.equals("cyan"))
name.setForeground(Color.cyan);
else
if(str.equals("black"))
name.setForeground(Color.black);
else
if(str.equals("blue"))
name.setForeground(Color.blue);
else
if(str.equals("gray"))
name.setForeground(Color.gray);
else
name.setForeground(Color.lightGray);
}
repaint();
}
public void itemStateChanged(ItemEvent ie)
{
String s=cbg.getSelectedCheckbox().getLabel();
if(s.equals("Background"))
f=1;
else
f=0;
repaint();
}
}


Other 4 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.