通过Java 画一个太极图
时间: 2023-06-19 19:05:41 浏览: 152
以下是Java代码实现太极图的过程:
```java
import java.awt.*;
import java.awt.geom.*;
public class TaiChi extends Frame {
private static final long serialVersionUID = 1L;
public TaiChi() {
super("太极图");
setSize(400, 400);
setBackground(Color.white);
setVisible(true);
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.translate(200, 200);
// 画圆
Ellipse2D.Double circle = new Ellipse2D.Double(-100, -100, 200, 200);
g2.draw(circle);
// 画两个半圆
Arc2D.Double arc1 = new Arc2D.Double(-100, -100, 200, 200, 90, 180, Arc2D.OPEN);
Arc2D.Double arc2 = new Arc2D.Double(-100, -100, 200, 200, -90, 180, Arc2D.OPEN);
g2.draw(arc1);
g2.draw(arc2);
// 画两个小圆
g2.setPaint(Color.white);
Ellipse2D.Double smallCircle1 = new Ellipse2D.Double(-50, -50, 50, 50);
Ellipse2D.Double smallCircle2 = new Ellipse2D.Double(0, -50, 50, 50);
g2.fill(smallCircle1);
g2.setPaint(Color.black);
g2.fill(smallCircle2);
// 画两个小点
g2.setPaint(Color.white);
Ellipse2D.Double smallPoint1 = new Ellipse2D.Double(-25, -25, 5, 5);
Ellipse2D.Double smallPoint2 = new Ellipse2D.Double(20, -25, 5, 5);
g2.fill(smallPoint1);
g2.setPaint(Color.black);
g2.fill(smallPoint2);
}
public static void main(String[] args) {
TaiChi tc = new TaiChi();
}
}
```
运行代码后,会弹出一个窗口,展示出太极图。
阅读全文