UNKNOWN //************************************** // 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 // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:None //This code is copyrighted and has limited warranties. //Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.7030/lngWId.2/qx/vb/scripts/ShowCode.htm //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(); } }