⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 画脸小程序.java

📁 画脸的一个小示范程序
💻 JAVA
字号:

import javax.swing.JPanel;
import java.awt.*;

public class SmilingFacePanel extends JPanel
{
   private final int BASEX = 120, BASEY = 60; // 画脸的起始点

      public SmilingFacePanel ()
   {
      setBackground (Color.blue);
      setPreferredSize (new Dimension(320, 200));
      setFont (new Font("Arial", Font.BOLD, 16));
   }

     //  开始画脸
   public void paintComponent (Graphics page)
   {
      super.paintComponent (page);

      page.setColor (Color.yellow);
      page.fillOval (BASEX, BASEY, 80, 80);  // 头
      page.fillOval (BASEX-5, BASEY+20, 90, 40);  // 耳朵

      page.setColor (Color.black);
      page.drawOval (BASEX+20, BASEY+30, 15, 7);  // 眼睛
      page.drawOval (BASEX+45, BASEY+30, 15, 7);

      page.fillOval (BASEX+25, BASEY+31, 5, 5);   // 嘴唇
      page.fillOval (BASEX+50, BASEY+31, 5, 5);

      page.drawArc (BASEX+20, BASEY+25, 15, 7, 0, 180);  // 眼眶
      page.drawArc (BASEX+45, BASEY+25, 15, 7, 0, 180);

      page.drawArc (BASEX+35, BASEY+40, 15, 10, 180, 180);  // 鼻子
      page.drawArc (BASEX+20, BASEY+50, 40, 15, 180, 180);  // 嘴巴

      page.setColor (Color.white);
      page.drawString ("Always remember that you are unique!",
                       BASEX-105, BASEY-15);
      page.drawString ("Just like everyone else.", BASEX-45, BASEY+105);
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -