/** * ColorApplet - this uses a ColorPanel to choose colors for a web page * size -- * at least 120 width x 120 height pixels * parameters -- * required for color bars - * "thickness" : thickness of the bars, "9" is the default * "background" : background color of page applet lives in, "808080" * * colors being chosen - * "c0","c1","c2","c3","c4","c5","c6" : * value "bgColor" means background, * value null (parameter not set) means end of parameters, * otherwise value given will be the text displayed * * public functions -- * getColor(int x) : get the xth color * setColor(int x, String c) : set the xth color * * architecture -- * ColorApplet (sets up children, processes parameters) * UseColor (how ColorPanel notifies ChoicePanel a color was chosen) * ColorPanel (a big hexagon) * ColorBar (three bars) * ColorHandle (a hexagon at the intersection of the three bars) * ChoicePanel (bunch of checkboxes) * ChoiceCheck */ import java.applet.*; import java.awt.*; import java.lang.*; import java.util.*; public final class ColorApplet extends Applet { ColorPanel c; /* the color panel */ ChoicePanel choices; /* checkboxes and panel that reflects choices */ String myColors[]; public String getColor(int x) { return choices.colors[x]; } public void setColor(int x, String newcolor) { if (newcolor == "") newcolor = null; choices.which = x; choices.UseColor(newcolor); } static Color s2c(String s) { return new Color(s==null ? 0x808080 : Integer.parseInt(s, 16)); } public void init() { Dimension d = this.size(); String param = getParameter("background"); Color outside = s2c(param); setLayout(new GridLayout(1,2,10,0)); setBackground(outside); setFont(new Font("TimesRoman", Font.PLAIN, getFont().getSize())); /* the choices, checkboxes and text */ choices = new ChoicePanel (this, Math.max(120, d.width-d.height-10), d.height); choices.names[0] = getParameter("c0"); choices.names[1] = getParameter("c1"); choices.names[2] = getParameter("c2"); choices.names[3] = getParameter("c3"); choices.names[4] = getParameter("c4"); choices.names[5] = getParameter("c5"); choices.names[6] = getParameter("c6"); choices.init(); add(choices); /* the color panel, chooses colors */ param = getParameter("thickness"); int thick = (param==null ? 9 : Integer.parseInt(param)); this.c = new ColorPanel( choices, outside, thick, d.width/2-11, d.height); add(c); } public void start() { c.start(); } public void stop() { c.stop(); } public void destroy() {} }