Creation of Color Palette and Image Loading DATE:3.08.10
Creation of Color Palette and Image Loading DATE:3.08.10
DATE:3.08.10
Aim:
To write a Applet program to create a color palette and create radio button for
selecting the foreground and background colors.
Hardware requirements:
Intel pentium Processor IV
128mb RAM
Software requirements:
Jdk1.6.0
Algorithm:
1. Create a color palette with a matrix of Buttons.
2. Create a TextArea control.
3. Create two Radiobutton for selecting the foreground and background colors.
4. Set the foreground of the TextArea with color specified by the Button which is
clicked only if the radiobutton selected is foreground
5. Otherwise set the background color of the TexeArea with color clicked.
COLOR PALLETE
PROGRAM:
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
cbg=new CheckboxGroup();
c1=new Checkbox("FOREGROUND",cbg,true);
c2=new Checkbox("BACKGROUND",cbg,false);
p1.add(c1);
p1.add(c2);
add(p1,BorderLayout.NORTH);
b1=new Button("RED");
b2=new Button("BLUE");
b3=new Button("GREEN");
p2.add(b1);
p2.add(b2);
p2.add(b3);
add(p2,BorderLayout.CENTER);
ta=new TextArea("DEMO FOR COLOR PALETTE",5,20);
p2.add(ta);
add(p3,BorderLayout.SOUTH);
//c1.addItemListener(this);
//c2.addItemListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
String str1=cbg.getSelectedCheckbox().getLabel();
System.out.println(str1);
if(str1.equals("FOREGROUND"))
{
if(str=="RED")
ta.setForeground(Color.red);
if(str=="BLUE")
ta.setForeground(Color.blue);
if(str=="GREEN")
ta.setForeground(Color.green);
}
else
{
if(str=="RED")
ta.setBackground(Color.red);
if(str=="BLUE")
ta.setBackground(Color.blue);
if(str=="GREEN")
ta.setBackground(Color.green);
}
}
}
OUTPUT:
RESULT:
Thus the program to create color pallete was executed and the output was
verified successfully.
IMAGE LOADING
PROGRAM:
import java.awt.*;
import java.applet.*;
import java.net.*;
/*
<applet code="ImageDemo" width=300 height=400>
</applet>
*/
public class ImageDemo extends Applet
{
Image img;
public void init()
{
img=getImage(getDocumentBase(),"Blue hills.jpg");
}
public void paint(Graphics g)
{
g.drawImage(img,0,0,this);
}
}
OUTPUT:
RESULT:
Thus the program to load an image was executed and the output was verified
successfully.