📄 stickfigure.java
字号:
//********************************************************************
// StickFigure.java Author: Lewis/Loftus
//
// Represents a graphical stick figure.
//********************************************************************
import java.awt.*;
public class StickFigure
{
private int baseX; // center of figure
private int baseY; // floor (bottom of feet)
private Color color; // color of stick figure
private int height; // height of stick figure
//-----------------------------------------------------------------
// Sets up the stick figure's primary attributes.
//-----------------------------------------------------------------
public StickFigure (int center, int bottom, Color shade, int size)
{
baseX = center;
baseY = bottom;
color = shade;
height = size;
}
//-----------------------------------------------------------------
// Draws this figure relative to baseX, baseY, and height.
//-----------------------------------------------------------------
public void draw (Graphics page)
{
int top = baseY - height; // top of head
page.setColor (color);
page.drawOval (baseX-10, top, 20, 20); // head
page.drawLine (baseX, top+20, baseX, baseY-30); // trunk
page.drawLine (baseX, baseY-30, baseX-15, baseY); // legs
page.drawLine (baseX, baseY-30, baseX+15, baseY);
page.drawLine (baseX, baseY-70, baseX-25, baseY-70); // arms
page.drawLine (baseX, baseY-70, baseX+20, baseY-85);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -