java必须知道的300个问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你好,我是 C 知道。关于你的问题,我可以回答。以下是 Java 编写玫瑰花程序的代码: ``` import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class Rose extends JPanel { private static final long serialVersionUID = 1L; public void paint(Graphics g) { int centerX = getWidth() / 2; int centerY = getHeight() / 2; int radius = 100; int petalCount = 6; double petalAngle = 2 * Math.PI / petalCount; double petalLength = 50; double petalWidth = 10; for (int i = ; i < petalCount; i++) { double angle = i * petalAngle; int x1 = (int) (centerX + radius * Math.cos(angle)); int y1 = (int) (centerY + radius * Math.sin(angle)); int x2 = (int) (centerX + (radius + petalLength) * Math.cos(angle)); int y2 = (int) (centerY + (radius + petalLength) * Math.sin(angle)); int x3 = (int) (centerX + (radius + petalLength) * Math.cos(angle + petalAngle / 2)); int y3 = (int) (centerY + (radius + petalLength) * Math.sin(angle + petalAngle / 2)); int x4 = (int) (centerX + (radius + petalLength) * Math.cos(angle + petalAngle)); int y4 = (int) (centerY + (radius + petalLength) * Math.sin(angle + petalAngle)); int[] xPoints = { x1, x2, x3, x4 }; int[] yPoints = { y1, y2, y3, y4 }; g.setColor(Color.RED); g.fillPolygon(xPoints, yPoints, 4); g.setColor(Color.GREEN); g.drawPolygon(xPoints, yPoints, 4); } } public static void main(String[] args) { JFrame frame = new JFrame("Rose"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 300); frame.setLocationRelativeTo(null); frame.add(new Rose()); frame.setVisible(true); } } ``` 希望能对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值