0

我必须只用一个 draw.oval 函数和 draw.arc 函数来完成这个项目。然而,我真的希望我能按照你的方式去做。这就是我现在所拥有的,但它仍然没有正确排列。有什么见解吗?谢谢!

//**********************************************************************
// Fish.Java    Louis Colucci
// Draws a rosetta
//**********************************************************************

import javax.swing.JApplet;

import java.awt.*;

public class Rosetta extends JApplet
{
    public void paint (Graphics page)
    {


        setBackground (Color.white);
        page.setColor (Color.black);


        //Draws the body

        page.drawOval(360, 360, 360,360);
        page.drawArc(360,180, 360,360,360,360);
        page.drawArc(360,540, 360,360,360,360);

        page.drawArc(525,435, 360,360,360,360);
        page.drawArc(525,285, 360,360,360,360);
        page.drawArc(195,435, 360,360,360,360);
        page.drawArc(195,285, 360,360,360,360);

    }

}
4

2 回答 2

1

就像是....

在此处输入图像描述

  1. 停止使用幻数,在渲染时使用实际已知值
  2. Call super.paint(...),这非常非常重要,如果不这样做,您最终会出现图形故障。事实上,使用 aJPanel并覆盖它的paintComponent方法并在那里自定义绘画(但不要忘记调用super.paintComponent

...

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.text.NumberFormat;
import javax.swing.JApplet;

public class Rosetta extends JApplet {

    public void paint(Graphics page) {

        super.paint(page);

        page.setColor(Color.black);

        int width = getWidth();
        int height = getHeight();

        int roseWidth = Math.min(width / 2, height / 2);
        int roseHeight = roseWidth;

        int centerX = width / 2;
        int centerY = height / 2;

        int x = (width - roseWidth) / 2;
        int y = (height - roseHeight) / 2;

        page.drawRect(x, y, roseWidth, roseHeight);
        page.drawOval(x, y, roseWidth, roseHeight);

        Graphics2D g2d = (Graphics2D) page;
        float angle = 30f;
        AffineTransform t = g2d.getTransform();
        g2d.transform(AffineTransform.getRotateInstance(Math.toRadians(angle), centerX, centerY));
        angle = 60f;
        for (int index = 0; index < 6; index++) {
            g2d.transform(AffineTransform.getRotateInstance(Math.toRadians(angle), centerX, centerY));
            g2d.drawArc(x + (roseWidth / 2), y, roseWidth, roseHeight, 360, 360);
        }
        g2d.transform(t);
    }

}
于 2013-10-02T07:26:00.840 回答
0

尝试这个:

import javax.swing.JApplet;
import java.awt.*;

public class Rosetta extends JApplet

{

public void paint(Graphics page)

       {
              final int MID = 130;
              final int TOP = 75;

              page.drawArc(MID,TOP-76,150,150,210,121);
              page.drawArc(MID,TOP+76,150,150,30,120);
              page.drawArc(MID+65,TOP+35,150,150,90,120);
              page.drawArc(MID-65,TOP+35,150,150,330,120);
              page.drawArc(MID-65,TOP-35,150,150,270,120);
              page.drawArc(MID+65,TOP-35,150,150,150,121);

              page.setColor(Color.red);
              page.drawOval(MID-1,TOP,151,151);
              }         
}
于 2014-09-29T02:14:46.217 回答