简体   繁体   English

Java:笑脸

[英]Java : smiley face

笑脸

I want to know what i should use to draw the mouth and eyes of the above smiley face. 我想知道我应该用什么来画出上面笑脸的嘴和眼睛。 so far i managed to draw whats behind the eyes and mouth (Look down for the result so far). 到目前为止,我设法在眼睛和嘴巴后面画出什么(看看目前为止的结果)。 i tried using Arc2D.double as you can see in the code down marked as a comment. 我尝试使用Arc2D.double,因为您可以在代码中看到标记为注释。

Here is what i made so far: 这是我到目前为止所做的:

import java.awt.geom.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class draw2 extends JPanel
{
  public void paintComponent(Graphics g)
 {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    this.setBackground(new Color( 255,255,255));

    g.setColor(Color.yellow);
    g.fillOval(100,100,300,300);

    g.setColor(Color.white);
    g.fillArc(110,120,250,250,90,180);

    g.setColor(new Color (218,165,32));
    g.drawArc(130,110,250,280,90,-180);

    g.setColor(Color.yellow);
    g.fillOval(125,105,250,290);

   // draw Arc2D.Double
    //g2.setColor(Color.black);
    //g2.fill(new Arc2D.Double(130, 200, 200,150,170, 200, Arc2D.OPEN));


}


    public static void main (String[] args)
    {
        JFrame f = new JFrame("Task 2");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        draw2 d = new draw2();
        f.add(d);
        f.setSize(600,600);
        f.setVisible(true);
    }

}

RESULT SO FAR: 结果如此:

在此输入图像描述

A starting point for the left and right laugh lines might be following snippet. 左右笑线的起点可能是以下片段。

BasicStroke stroke = new BasicStroke(
        12,
        BasicStroke.CAP_BUTT,
        0,
        BasicStroke.JOIN_BEVEL
);
g2.setStroke(stroke);

GeneralPath leftLaughLine = new GeneralPath();
int x = 150;
int y = 230;
leftLaughLine.moveTo(x, y);
leftLaughLine.curveTo(x - 20, y + 5, x - 25, y + 25, x - 25, y + 25);
g2.draw(leftLaughLine);

GeneralPath rigthLaughLine = new GeneralPath();
x = 350;
y = 230;
rigthLaughLine.moveTo(x, y);
rigthLaughLine.curveTo(x + 20, y + 5, x + 25, y + 25, x + 25, y + 25);
g2.draw(rigthLaughLine);

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM