我真的被困在如何编程这个.如何在Java中用半径绘制一个圆并围绕边缘指向?
我需要在具有半径的JFrame中绘制一个圆并围绕圆周指向.我可以在数学上计算如何找到边缘点的坐标,但我似乎无法编程圆.我目前正在使用Ellipse2D方法,但这似乎不起作用并且不返回半径,因为根据我的理解,它不从中心绘制圆而是使用高度和宽度从起始坐标绘制.
我当前的代码是在一个单独的框架上,但我需要将它添加到我现有的框架.
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
public class circle extends JFrame {
public circle() {
super("circle");
setSize(410, 435);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Panel sp = new Panel();
Container content = getContentPane();
content.add(sp);
setContentPane(content);
setVisible(true);
}
public static void main (String args[]){
circle sign = new circle();
}
}
class Panel extends JPanel {
public void paintComponent(Graphics comp) {
super.paintComponent(comp);
Graphics2D comp2D = (Graphics2D) comp;
comp2D.setColor(Color.red);
Ellipse2D.Float sign1 = new Ellipse2D.Float(0F, 0F, 350F, 350F);
comp2D.fill(sign1);
}
}
Run Code Online (Sandbox Code Playgroud)