构造函数(java.awt.Polygon)未定义

构造函数(java.awt.Polygon)未定义,java,Java,这里我的代码返回错误:构造函数VectorSprite(java.awt.Polygon)未定义 import java.awt.Polygon; public class Rock extends VectorSprite{ int size; public Rock(){ super(new Polygon(new int[] {20, 15, 30 ,50, 40, 35}, new int[]{5, 30, 45, 15, 10, 5},6)); //

这里我的代码返回错误:构造函数VectorSprite(java.awt.Polygon)未定义

import java.awt.Polygon;


public class Rock extends VectorSprite{
    int size;
    public Rock(){
      super(new Polygon(new int[] {20, 15, 30 ,50, 40, 35}, new int[]{5,  30,  45, 15, 10, 5},6)); //error here

        velocityx = (float)Math.random() * 6 - 3;
        velocityy = (float)Math.random() * 6 - 3;

    }

    public Rock (int size){
        this();
        this.size = size;
    }
    @Override
    public void updatePosition(){
        angle += Math.PI/180;
      super.updatePosition();
    }
    public void rockspawn(float x, float y){
       float randAng;
       randAng = (float)Math.random() * (float)Math.PI * 2;

       posx = x + ((float)Math.cos(randAng)*150);
       posy = y + ((float)Math.sin(randAng)*150);

    }
}
VectorSprite的构造函数给出了错误。看起来是这样的:

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;

public class VectorSprite {
    float posx;
    float posy;
    Color color;
    Polygon shape;
    float velocityx;
    float velocityy;
    double angle;

int[] xp = {20,50 ,30 };
int[] yp = {15,10 ,30 };

    public VectorSprite(){
    posx = 30;
    posy = 30;
    color = Color.GREEN;
    shape = new Polygon(xp,yp,3);
    velocityx = 0;
    velocityy = 0;
    }
   public void draw(Graphics g) {
       g.drawPolygon(shape);
   }
   public void updatePosition() {
      posx = posx + velocityx  ;  
      for (int i = 0; i < shape.npoints; i++){
        shape.xpoints[i] += velocityx;
        shape.ypoints[i] += velocityy;

      }         
}

}
导入java.awt.Color;
导入java.awt.Graphics;
导入java.awt.Polygon;
公共类矢量精灵{
浮动posx;
浮标;
颜色;
多边形形状;
浮动速度x;
浮动速度y;
双角度;
int[]xp={20,50,30};
int[]yp={15,10,30};
公共矢量精灵(){
posx=30;
posy=30;
颜色=颜色。绿色;
形状=新多边形(xp,yp,3);
速度x=0;
速度y=0;
}
公共空间绘制(图g){
g、 绘制多边形(形状);
}
public void updatePosition(){
posx=posx+速度x;
对于(int i=0;i

这里有什么问题?我很抱歉说得这么含糊,但这真的是旧代码,我是全新的现场。我将尝试回答任何澄清问题。

查看完整的错误消息,并将其张贴在此处(您当前没有这样做),因为它会准确地告诉您错误所在。然后查看多边形API,看看实际上允许哪些构造函数。这是完整的错误消息。除此之外,它没有说其他任何东西。啊,我的错——矢量精灵有接受多边形的构造函数吗?如果是,请给我们看看。您的代码假定它在调用
super(…)
传递多边形时执行。如果它没有这个构造函数,那么你就不能这么做,纯粹的和简单的。也许你想这么做——给VectorSprite这样一个构造函数,然后用它来设置类的多边形字段。好吧,我是个白痴。我刚刚摆脱了super(),现在它可以工作了。你是对的。谢谢