我应该添加一个多边形橙色鼻子和一个多边形黑帽子,以及写给他的围巾,但无法弄明白。这就是我到目前为止所拥有的。我似乎无法想象我是否需要使用fillpolygon或什么。
import java.applet.Applet;
import java.awt.*;
public class SnowMan extends Applet
{
public void paint (Graphics frame)
{
// set up some constants
final int MID = 150; // middle of the snowman
final int TOP = 50; // top of the snowman
// need to set the background colors
setBackground (Color.cyan);
// color the ground
frame.setColor (Color.lightGray);
// the ground is a blue rectangle
frame.fillRect (1, 175, 500, 150) ;
// draw three large snowballs to make up snowman
frame.setColor (Color.white);
// draw head
frame.fillOval (MID - 20, TOP, 40, 40);
// draw middle (upper torso)
frame.fillOval (MID - 35, TOP + 35, 70, 50);
// draw base (lower torso)
frame.fillOval (MID - 50, TOP + 80, 100, 60);
// draw in features of snowman
frame.setColor (Color.black);
// draw eyes
// draw left eye
frame.fillOval (MID - 10, TOP + 10, 5, 5);
// draw right eye
frame.fillOval (MID + 5, TOP + 10, 5, 5);
//Draw Buttons
frame.fillOval (MID -2, TOP + 50, 5, 5);
frame.fillOval (MID -2, TOP + 60, 5, 5);
frame.fillOval (MID -2, TOP + 70, 5, 5);
// draw arms
// draw left arm
frame.drawLine (MID - 25, TOP + 60, MID - 50, TOP + 40);
// draw right arm
frame.drawLine (MID + 25, TOP + 60, MID + 55, TOP + 60);
// draw hat
// draw brim of hat
frame.drawLine (MID - 20, TOP + 5, MID + 20, TOP + 5);
frame.fillRect (MID - 20, TOP + 35, 40, 10);
// draw top of hat
frame.fillRect (MID - 15, TOP - 20, 30, 25);
frame.setColor (Color.red);
// draw mouth
frame.drawArc (MID - 10, TOP + 20, 20, 10, 190, 160);
}
}
答案 0 :(得分:0)
只需创建一个多边形并绘制它
Error: Could not find or load main class org.elasticsearch.tools.JavaVersionChecker
Elasticsearch requires at least Java 8 but your Java version from /bin/java does not meet this requirement
您必须将鼻子设置在正确的位置,因此您必须调整public void paint (Graphics frame)
{
...
//three points form a nose
int[] xs = new int[]{10, 0,10};
int[] yx = new int[]{0, 10,10}; //uhm - ugly triangle 'carrot' nose
//TODO: set color before drawing
//create polygon from three points
Polygon p = new Polygon(xs, ys, 3);
//draw the polygon
frame.fill(p);
}
和xs
值......