0% found this document useful (0 votes)
32 views

Creation of Color Palette and Image Loading DATE:3.08.10

This document describes two Java applet programs: 1. A color palette program that creates radio buttons to select foreground and background colors for a text area. Buttons allow selecting red, blue, or green and setting the appropriate color. 2. An image loading program that gets an image from the document base and draws it using drawImage(). When executed, the output was successfully verified.

Uploaded by

Renuka C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Creation of Color Palette and Image Loading DATE:3.08.10

This document describes two Java applet programs: 1. A color palette program that creates radio buttons to select foreground and background colors for a text area. Buttons allow selecting red, blue, or green and setting the appropriate color. 2. An image loading program that gets an image from the document base and draws it using drawImage(). When executed, the output was successfully verified.

Uploaded by

Renuka C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

CREATION OF COLOR PALETTE AND IMAGE LOADING

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.*;

/*<applet code="Cpdemo" width=500 height=600>


</applet>
*/
public class Cpdemo extends Applet implements ActionListener
{
Panel p1,p2,p3;
Checkbox c1,c2;
CheckboxGroup cbg;
TextArea ta;
Button b1,b2,b3;

public void init()


{
setLayout(new BorderLayout());

p1=new Panel(new FlowLayout());


p2=new Panel(new GridLayout(2,2));
p3=new Panel(new FlowLayout(FlowLayout.CENTER));

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.

You might also like