文档介绍:一:基本原理利用 Java 2D 的 Area 对象对绘制形状几何操作的支持,完成太极图案的绘制,使用 Pain t 来完成对不同颜色的填充。 Java 2D 图形 API Area 对 Shape 支持四种几何操作: - Add (加) - 保留两个几何形状及其重叠部分- Subtract (减)–从第一个几何形状上减去和第二个重叠的部分, 保留减去之后的第一个几何形状- Intersect (与)–只保留两个几何形状重叠的部分。- ExclusiveOr( 或)–保留他们相互不重叠的部分。参看下图: 二:程序运行效果程序基于 JDK6 API 完成程序源代码如下: [java] view plain copy 1. .; 2. 3. import ; 4. import ; 5. import ; 6. import ; 7. import ; 8. import ; 9. import ; 10. import ; 11. import ; 12. import ; 13. import ; 14. import ; 15. 16. import ; 17. import ; 18. import ; 19. 20. public class YingYangGraphics extends JComponent { 21. 22. /** 23. * 24. */ 25. private static final long serialVersionUID = 8812325148970066491L; 26. private BufferedImage image = null ; 27. public YingYangGraphics() { 28. super (); 29. this .setOpaque( false ); 30. } 31. protected void ponent(Graphics g) { 32. Graphics2D g2 = (Graphics2D)g; 33. (, RenderingHints. VALUE_ANTIALIAS_ON); 34. (getImage(), 0,0, (), (), null ); 35. Shape lefthalfCirle = new ( 10 ,