fork download
  1. package Lib;
  2.  
  3. import java.awt.*;
  4. import javax.swing.*;
  5.  
  6. public class FormLab13_1 extends JFrame {
  7. public FormLab13_1() {
  8. setTitle("Smiling Man");
  9. setSize(350, 420); // ปรับขนาดหน้าต่างให้พอดี
  10. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  11. setLocationRelativeTo(null);
  12. add(new DrawFace());
  13. setVisible(true);
  14. }
  15.  
  16. class DrawFace extends JPanel {
  17. @Override
  18. protected void paintComponent(Graphics g) {
  19. super.paintComponent(g);
  20.  
  21. // ตั้งค่าสีพื้นหลัง
  22. setBackground(Color.WHITE);
  23.  
  24. // วาดข้อความ
  25. g.setFont(new Font("Tahoma", Font.BOLD, 20));
  26. g.drawString("Just Keep Smiling", 80, 40);
  27.  
  28. // วาดใบหน้า
  29. g.setColor(Color.BLACK);
  30. g.drawOval(75, 60, 190, 190);
  31.  
  32. // วาดดวงตา
  33. g.fillOval(130, 110, 30, 30); // ตาซ้าย
  34. g.fillOval(170, 110, 30, 30); // ตาขวา
  35.  
  36. // วาดปาก
  37. g.drawArc(120, 170, 100, 40, 0, -180);
  38.  
  39. // วาดโบว์
  40. int[] xLeft = { 100, 180, 100 };
  41. int[] yLeft = { 270, 250, 230 };
  42.  
  43. int[] xRight = { 170, 250, 250 };
  44. int[] yRight = { 250, 230, 270 };
  45.  
  46. g.fillPolygon(xLeft, yLeft, 3); // สามเหลี่ยมซ้าย
  47. g.fillPolygon(xRight, yRight, 3); // สามเหลี่ยมขวา
  48. }
  49. }
  50. }
Success #stdin #stdout 0.03s 25936KB
stdin
Standard input is empty
stdout
package Lib;

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

public class FormLab13_1 extends JFrame {
    public FormLab13_1() {
        setTitle("Smiling Man");
        setSize(350, 420); // ปรับขนาดหน้าต่างให้พอดี
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        add(new DrawFace());
        setVisible(true);
    }

    class DrawFace extends JPanel {
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);

            // ตั้งค่าสีพื้นหลัง
            setBackground(Color.WHITE);

            // วาดข้อความ
            g.setFont(new Font("Tahoma", Font.BOLD, 20));
            g.drawString("Just Keep Smiling", 80, 40);

            // วาดใบหน้า
            g.setColor(Color.BLACK);
            g.drawOval(75, 60, 190, 190);

            // วาดดวงตา
            g.fillOval(130, 110, 30, 30); // ตาซ้าย
            g.fillOval(170, 110, 30, 30); // ตาขวา

            // วาดปาก
            g.drawArc(120, 170, 100, 40, 0, -180);

            // วาดโบว์
            int[] xLeft = { 100, 180, 100 };
            int[] yLeft = { 270, 250, 230 };

            int[] xRight = { 170, 250, 250 };
            int[] yRight = { 250, 230, 270 };

            g.fillPolygon(xLeft, yLeft, 3); // สามเหลี่ยมซ้าย
            g.fillPolygon(xRight, yRight, 3); // สามเหลี่ยมขวา
        }
    }
}