java开发爱心代码示例,绘制心形图形的步骤解析
import java.awt.;
import javax.swing.;
public class Heart extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.RED);
int[] x = {75, 100, 125, 100};
int[] y = {100, 75, 100, 125};
g2d.fillOval(50, 50, 50, 50);
g2d.fillOval(100, 50, 50, 50);
g2d.fillPolygon(x, y, 4);
}
}
下载地址
用户评论