我必须使用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);
}
}
答案 0 :(得分:1)
像......那样的东西。
super.paint(...)
,这非常非常重要,如果不这样做,最终会出现图形故障。事实上,使用JPanel
并覆盖其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);
}
}
答案 1 :(得分: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);
}
}