这是我的代码。我之前使用过Ellipse2D.Double,所以这很......很奇怪。
import java.awt.*;
import javax.swing.JComponent;
import java.awt.geom.Ellipse2D.Double;
public class Benzene extends JComponent
{
int size = 75;
public void paintComponent(Graphics g){
Graphics2D g2 = (Graphics2D) g;
drawHex(size, g2);
drawCircle(size, g2);
}
public void drawHex(int size, Graphics2D g2){
Polygon hexagon = new Polygon();
Rectangle drawTest = new Rectangle(100,100,100,100);
g2.draw(drawTest);
}
public void drawCircle(int size, Graphics2D g2){
Ellipse2D.Double circle = new Ellipse2D.Double(100,100,size,size);
g2.draw(circle);
}
}
我该如何解决此错误?不确定我做错了什么。
答案 0 :(得分:1)
您必须导入Ellipse2D
而不是Ellipse2D.Double
。由于Ellipse2D.Double是在当前代码中导入的,因此Java希望您将其引用为Double
(这会引起混淆)。如果您只是将其更改为import java.awt.geom.Ellipse2D;