Follow Me
Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts
          I hope you have all used MS-PAINT, GIMP, etc to draw pictures in your childhood. Here I would like to share how to draw a face using Java programming. In this program I have used JFrame, JPanel, Color and Graphics library to draw the face.


          Video Tutorial

          The source code

import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;

/*

    Coded By Ajith Kp [ ajithkp560 ]
    (C) » GPU SMACKERS ™ (C)

*/
public class FaceDrawApp extends JPanel{
    public void paintComponent(Graphics g)
    {
        //Draw Face
        g.setColor(Color.BLUE);
        g.drawOval(100, 100, 300, 400);
        
        //Draw EyeBrow
        g.setColor(Color.GREEN);
        g.drawRect(170, 190, 70, 5);
        g.drawRect(270, 190, 70, 5);
        
        //Draw Eyes
        g.setColor(Color.CYAN);
        g.drawOval(175, 200, 60, 40);
        g.drawOval(195, 210, 20, 20);
        g.drawOval(275, 200, 60, 40);
        g.drawOval(295, 210, 20, 20);
        
        //Draw Nose
        g.setColor(Color.RED);
        g.drawOval(240, 255, 40, 70);
        
        //Draw Lips
        g.setColor(Color.PINK);
        g.drawOval(180, 350, 150, 30);
        g.drawLine(180, 365, 330, 365);
        
        //Draw Ears
        g.setColor(Color.ORANGE);
        g.drawOval(75, 250, 25, 100);
        g.drawOval(400, 250, 25, 100);
        
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        JFrame fda = new JFrame("FaceDrawApp by Ajith Kp [ ajithkp560 ]");
        fda.setBackground(Color.BLACK);
        fda.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        fda.setVisible(true);
        fda.setSize(500, 700);
        fda.add(new FaceDrawApp());
    }
    
}

Contact Form

Name

Email *

Message *

Labels

Translate