帮我写一个java炫酷爱心代码
时间: 2023-04-02 18:05:09 浏览: 210
好的,以下是一个简单的Java炫酷爱心代码:
```
import java.awt.*;
import javax.swing.*;
public class Heart extends JFrame {
public Heart() {
setSize(500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setStroke(new BasicStroke(2));
g2d.setColor(Color.RED);
int x = 200;
int y = 200;
int width = 100;
int height = 100;
int controlX1 = x - width / 2;
int controlY1 = y - height / 2;
int controlX2 = x + width / 2;
int controlY2 = y - height / 2;
g2d.fillArc(controlX1, controlY1, width, height, , 180);
g2d.fillArc(controlX2, controlY2, width, height, , 180);
int[] xPoints = {x, x + width / 2, x - width / 2};
int[] yPoints = {y + height / 2, y - height / 2, y - height / 2};
g2d.fillPolygon(xPoints, yPoints, 3);
}
public static void main(String[] args) {
new Heart();
}
}
```
阅读全文