EX. NO: 7 Colour Palette Design Date:: Step 1
EX. NO: 7 Colour Palette Design Date:: Step 1
ALGORITHM:
STEP 1: Import all necessary packages and classes
STEP 2: Define a class that extends frame and implements action listener
STEP 3: Declare an array of buttons to set colours, two checkboxes for foreground And
background colours.
STEP 4: Declare three panels, button panel, palette panel and check panel
STEP 5: In the class constructor do the following:
STEP 6: In the actionPerformed() method, add the text of all the text fields to the text area
STEP 7: Add the text area, button panel, and check panel to various zones of the
border layout
STEP 8: Define a Window Adapter class and handle the window closing event
PROGRAM:
import java.awt.*;
import java.applet.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.*;
public class app extends Applet implements ActionListener,ItemListener
{
boolean toggle =false;
CheckboxGroup backOrFore;
Checkbox fore;
Checkbox back;
public void init () {
RA1411003010692
Button yellow = new Button("yellow");
this.add(l1);
this.add(back);
this.add(fore);
this.add(red);
this.add(orange);
this.add(yellow);
red.addActionListener(this);
orange.addActionListener(this);
yellow.addActionListener(this);
back.addItemListener(this);
fore.addItemListener(this);
}
public void itemStateChanged (ItemEvent ie)
{
if(back.getState() == true)
toggle=true;
else
toggle = false;
}
public void actionPerformed(ActionEvent ae){
if(action.equals("red"))
{
System.out.println("Red is pressed");
if(toggle==true)
this.setBackground(Color.red);
else
this.setForeground(Color.red);
repaint();
}
else if(action.equals("orange"))
{
System.out.println("orange is pessed");
if(toggle==true)
this.setBackground(Color.orange);
else
this.setForeground(Color.orange);
repaint();
}
RA1411003010692
else if(action.equals("yellow"))
{
System.out.println("yellow is pessed");
if(toggle==true)
this.setBackground(Color.yellow);
else
this.setForeground(Color.yellow);
repaint();
}
else if(action.equals("back"))
{
System.out.println("back is pessed");
}
else if(action.equals("fore"))
{
System.out.println("fore is pessed");
}
}
public void paint(Graphics g)
{
//g.drawString("Select background or foreground", 20, 20);
RESULT:
Thus the program to demonstrate colour palette is implemented and executed successfully.
RA1411003010692