Home Tutorial Java Swing Create Human Face using Graphics

 
 

Share on Google+Share on Google+
Create Human Face using Graphics
Posted on: January 16, 2010 at 12:00 AM
Advertisement
In this section, you will learn how to create human face using Graphics.

Create Human Face using Graphics

In this section, you will learn how to create human face using Graphics. A Graphics provides contexts that allow an application to draw onto components that are realized on various devices, as well as onto off-screen images. The Graphics class provides several methods through which we have given different shapes to eyes, nose and mouth.

Here is the code:

import java.awt.*;
import java.applet.*;

public class HumanFace extends Applet {
	private int mouseX, mouseY;
	private boolean mouseclicked = false;

	public void init() {
	}

	public void paint(Graphics g) {
		g.drawOval(40, 40, 120, 150);
		g.drawOval(57, 75, 30, 30);
		g.drawOval(110, 75, 30, 30);
		g.fillOval(68, 81, 10, 10);
		g.fillOval(121, 81, 10, 10);
		g.drawLine(100, 100, 100, 117);
		g.fillRect(60, 139, 80, 10);
		if (mouseclicked) {
			g.clearRect(60, 139, 80, 10);
			g.drawArc(70, 100, 60, 60, 0, -180);
			mouseclicked = false;
		}

	}

	public boolean mouseDown(Event e, int x, int y) {
		mouseX = x;
		mouseY = y;
		mouseclicked = true;
		repaint();
		return true;
	}
}

applet.html:

<html>
<body>
<h1>Java Applet Demo</h1>
<applet code=HumanFace.class width=500 height=350>
</applet>
</body>
</html>
Advertisement

Related Tags for Create Human Face using Graphics:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 16, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com