Ошибка несовместимых типов GeneralPath не может быть преобразован в Shape - PullRequest
0 голосов
/ 11 апреля 2020

Я рисую фигуру в java и вот код:

 public void paint(Graphics g){
        g.setColor(Color.BLACK);
        Font ft =new Font("TimeNeoRoman",6,60);
        g.setFont(ft);
        g.drawString("My Event", 250, 40);
        int x[] ={500,267,6,109,73,83,55,27,37,1,43};
        int y[]={0,236,36,54,96,72,96,54,36,36};

        Graphics2D g2=(Graphics2D)getGraphics();
        Graphics2D g3=(Graphics2D)getGraphics();
        Graphics2D g4=(Graphics2D)getGraphics();
        Graphics2D g5=(Graphics2D)getGraphics();
        GeneralPath star = new GeneralPath();
        star.moveTo(x[0], y[0]);
        for(int k=1;k<=x.length;k++){
            star.lineTo(x[k], y[k]);
            star.closePath();
            g.translate(200, 200);
            g2.translate(800, 200);
            g3.translate(800,500);
            g4.translate(500, 200);
        for(int j=1;j<=20;j++){
            ((Graphics2D) g).rotate(Math.PI/10.0);
            g.setColor(new Color((int)(Math.random()*256),(int)(Math.random()*256),
            (int)(Math.random()*256)));
          ((Graphics2D) g).fill(star);
          g2.rotate(Math.PI/10.0);
          g2.setColor(new Color((int)(Math.random()*256),(int)(Math.random()*256),
            (int)(Math.random()*256)));
            g2.fill(star);
        }
        }

Ошибка в строке

((Graphics2D) g).fill(star);

и

 g2.fill(star);

Почему это показывает мне ошибку "несовместимые типы" и как я могу это исправить Пожалуйста, помогите мне

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...