93 g2.setPaint(c);
94 g2.fill(r);
95 }
96 // 在3层的最外围绘制一个框
97 y -= size * 2;
98 Rectangle2D frame = new Rectangle2D.Float(x, y, size * colors.length,
99 size * 3);
100 g2.setPaint(Color.black);
101 g2.draw(frame);
102 g2.translate(-d.width / 2, -d.height * 5 / 8);
103 }
104 // 绘制带纹理的着色
105 private void paintTexture(Graphics g) {
106 Graphics2D g2 = (Graphics2D) g;
107 BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB);
108 Graphics2D big = bi.createGraphics();
109 big.setColor(Color.blue);
110 big.drawRect(0, 0, 5, 5);
111 big.setColor(Color.lightGray);
112 big.fillOval(0, 0, 5, 5);
113 Rectangle r = new Rectangle(0, 0, 5, 5);
114 g2.setPaint(new TexturePaint(bi, r));
115 // 用带有纹理的TexturePaint绘制rect。
116 Rectangle rect = new Rectangle(5, 5 + getHeight() * 3 / 4, 100, 100);
117 g2.fill(rect);
118 big.dispose();
119 }
120 }