import java.awt.*; import java.awt.event.*; import java.applet.*; import java.util.*; import java.lang.*; /** * ColorHandle - draw a hexagon of the chosen color at the right spot. * * This is strictly a helper class for ColorPanel */ import java.awt.*; final class ColorHandle { final int hx[]; /* handle hexagon, centered at 0 */ final int hy[]; int hcx[]; int hcy[]; ColorPanel b; /* initializer */ ColorHandle(ColorPanel b) { this.b = b; int thick = b.thickness; if (b.size().width > b.size().height) { hx = new int[] {0, thick, thick, 0, -thick, -thick}; hy = new int[] {thick, thick/2, -thick/2, -thick, -thick/2, thick/2}; } else { hx = new int[] {thick, thick/2, -thick/2, -thick, -thick/2, thick/2}; hy = new int[] {0, thick, thick, 0, -thick, -thick}; } hcx = new int[6]; hcy = new int[6]; } void clear(Graphics g) { g.fillPolygon(hcx, hcy, 6); g.drawLine(hcx[5],hcy[5], hcx[0],hcy[0]); g.drawLine(hcx[0],hcy[0], hcx[1],hcy[1]); g.drawLine(hcx[1],hcy[1], hcx[2],hcy[2]); g.drawLine(hcx[2],hcy[2], hcx[3],hcy[3]); g.drawLine(hcx[3],hcy[3], hcx[4],hcy[4]); g.drawLine(hcx[4],hcy[4], hcx[5],hcy[5]); } /* draw the handle */ void draw(Graphics g) { for (int i=0; i<6; ++i) { hcx[i]=hx[i]+b.currx; hcy[i]=hy[i]+b.curry; } Color c = new Color(b.cc); g.setColor(c); g.fillPolygon(hcx, hcy, 6); g.setColor(Color.black); g.drawLine(hcx[5],hcy[5], hcx[0],hcy[0]); g.drawLine(hcx[0],hcy[0], hcx[1],hcy[1]); g.drawLine(hcx[1],hcy[1], hcx[2],hcy[2]); g.setColor(Color.white); g.drawLine(hcx[2],hcy[2], hcx[3],hcy[3]); g.drawLine(hcx[3],hcy[3], hcx[4],hcy[4]); g.drawLine(hcx[4],hcy[4], hcx[5],hcy[5]); } }