Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 爪哇:笑脸_Java_Graphics - Fatal编程技术网

Java 爪哇:笑脸

Java 爪哇:笑脸,java,graphics,Java,Graphics,我想知道我应该用什么来画上面笑脸的嘴和眼睛。到目前为止,我成功地画出了眼睛和嘴巴后面的东西(向下看,直到目前为止的结果)。我尝试使用了Arc2D.double,正如您在标记为注释的代码中看到的那样 以下是我迄今为止所做的: import java.awt.geom.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class draw2 extends JPanel { public vo

我想知道我应该用什么来画上面笑脸的嘴和眼睛。到目前为止,我成功地画出了眼睛和嘴巴后面的东西(向下看,直到目前为止的结果)。我尝试使用了Arc2D.double,正如您在标记为注释的代码中看到的那样

以下是我迄今为止所做的:

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);
    }

}
迄今为止的结果:


左右笑线的起点可能是以下片段

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);

到目前为止,这是一次很好的尝试和mvce……)@乔迪卡斯蒂拉谢谢你,但我现在陷入困境。别担心,有人会指引你正确的方向,我已经检查了Arch2D,似乎是一个很好的方法。。。但我几乎是。。。图表并不是我的最佳技能,但我能回答这个问题clearer@JordiCastilla看起来好多了,谢谢!