answersLogoWhite

0


Best Answer

/* <applet code=palette height=600 width=600>

</applet> */

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

public class palette extends Applet implements ActionListener,ItemListener

{

Button[] colors;

Checkbox foreground,background;

TextArea workarea;

CheckboxGroup cbg;

Panel buttonpanel,checkpanel,palettepanel;

String colour;

public void init()

{

buttonpanel=new Panel();

buttonpanel.setLayout(new GridLayout(3,3));

colors=new Button[9];

colors[0]=new Button("RED");

colors[1]=new Button("GREEN");

colors[2]=new Button("BLUE");

colors[3]=new Button("CYAN");

colors[4]=new Button("ORANGE");

colors[5]=new Button("WHITE");

colors[6]=new Button("BLACK");

colors[7]=new Button("YELLOW");

colors[8]=new Button("PINK");

for(int i=0;i<9;i++)

{

colors[i].addActionListener(this);

buttonpanel.add(colors[i]);

}

checkpanel=new Panel();

checkpanel.setLayout(new FlowLayout());

cbg=new CheckboxGroup();

foreground=new Checkbox("ForeGround",cbg,true);

background=new Checkbox("BackGround",cbg,false);

foreground.addItemListener(this);

background.addItemListener(this);

checkpanel.add(foreground);

checkpanel.add(background);

workarea=new TextArea(8,40);

workarea.setFont(new Font("Garamond",Font.BOLD,20));

palettepanel=new Panel();

palettepanel.setLayout(new BorderLayout());

palettepanel.add(workarea,BorderLayout.CENTER);

palettepanel.add(checkpanel,BorderLayout.EAST);

palettepanel.add(buttonpanel,BorderLayout.SOUTH);

add(palettepanel);

}

public void itemStateChanged(ItemEvent ie)

{

}

public void actionPerformed(ActionEvent ae)

{

colour=ae.getActionCommand();

if(foreground.getState()==true)

workarea.setForeground(getColour());

if(background.getState()==true)

workarea.setBackground(getColour());

}

public Color getColour()

{

Color mycolor=null;

if(colour.equals("RED"))

mycolor=Color.red;

if(colour.equals("GREEN"))

mycolor=Color.green;

if(colour.equals("BLUE"))

mycolor=Color.blue;

if(colour.equals("CYAN"))

mycolor=Color.cyan;

if(colour.equals("ORANGE"))

mycolor=Color.orange;

if(colour.equals("WHITE"))

mycolor=Color.white;

if(colour.equals("BLACK"))

mycolor=Color.black;

if(colour.equals("YELLOW"))

mycolor=Color.yellow;

if(colour.equals("PINK"))

mycolor=Color.pink;

return mycolor;

}

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

getting the code

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: To Write program in Java to create applets to Create a color palette with matrix of buttons using applet viewer?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why swing used insted of applet?

Swing is used for desktop applications. Applets are used to create program which run in a browser.


What is applet in javahow it works?

Applets allow you to do frontend in java. You can draw things like rectangle,circle etc or create buttons and textboxes or you could even create a game! You can make use of the powerful api of java to design the applet and make use of awk(abstract window kit).


Do you need netbeans to create java applets for your website?

No, you just need to know how to type manually the code. Netbeans, instead, can type the code for your.


How do you create a e-passport website using java swing?

You really don't want to do that. Swing is for desktop applications. If you want to create a website, use Java Server Faces or Applets, not Swing.


How do you create monochromatic colors?

I am wearing monochromatic today. I am wearing red, pink, and deep red. Add white and add a shade to create that monochromatic palette.


How do you create a player on Poptropica?

Go to poptropica then there will be two buttons with one of them saying "create" or something


What are the release dates for Color Splash - 2007 A Light Palette and Rustic Elements Create a Seaside Feel in a Bedroom Makeover 5-6?

Color Splash - 2007 A Light Palette and Rustic Elements Create a Seaside Feel in a Bedroom Makeover 5-6 was released on: USA: 7 February 2009


How do you create and use tools from objects and images in gstarcad?

You can create a tool by dragging objects from your drawing onto a tool palette. You can then use the new tool to create objects with the same properties as the object you dragged onto the tool palette.Tool palettes are tabbed areas within the Tool Palettes window. The items you add to a tool palette are called tools. You can create a tool by dragging any of the following, one at a time, onto your tool palette:Geometric objects such as lines, circles, and polylinesDimensionsBlocksHatchesSolid fillsGradient fillsRaster imagesExternal references (xrefs)You can then use the new tool to create objects in your drawing with the same properties as the object you dragged to the tool palette. For example, if you drag a red circle with a lineweight of .05 mm from your drawing to your tool palette, the new tool creates a red circle with a lineweight of .05 mm. If you drag a block or xref to a tool palette, the new tool inserts the block or xref with the same properties into your drawing.When you drag a geometric object or a dimension onto a tool palette, the new tool is automatically created with an appropriate flyout. Dimension tool flyouts, for example, provide an assortment of dimension styles. Click the arrow on the right side of the tool icon on the tool palette to display the flyout. When you use a tool on a flyout, the object in the drawing has the same properties as the original tool on the tool palette.


What is a program that allows you to create written program?

word processing program


Write a program to create a maze?

this is to write or create


How do you create a program that can input 100 names using flowchart?

create a program that can input 100 names


Can you use buttons on the Insert tab of the Ribbon to create and modify a chart?

true