Androidberry logo Androidberry text logo
AndroidBerry Home
  • Learn Java
  • Java Programs
  • Interview Questions
  • Androidberry facebook
  • Androidberry twitter
  • Androidberry google plus

Java Tutorials


Basic Introduction

Decision Making

Looping

Classes and Objects

Inheritance

Interface

Packages

Exception Handling

Multithreading

Java Applets

What is Applet?
Java Applet vs Application
Creating a Applet
Displaying Applet on Webpage
Applet Lifecycle
Applet Tag
Passing Parameters to Applet
Setting Color to applet
Update and Repaint method
Using Fonts in Applet

Graphics Programming

Intro. to Graphics class
Drawing - Lines , Rectangles
Drawing - Circles and Ellipse
Drawing - Arcs
Drawing - Polygons
Drawing - Bar Charts

More on Java

Java Programs
Java Keywords Dictionary
Java Interview Questions

Java Drawing Circle and Ellipse


Java applet has drawOval() method to draw both circle and ellipse on the applet window.

Java also has fillOval () method to draw filled oval.

Syntax

g.drawOval(int x,int y,int width,int height);
g.fillOval(int x,int y,int width,int height);

The Both method takes 4 arguments, first two represents the top left corners and other two represents width and height of oval.

Circle

If width and height arguments are same, then oval becomes circle.

Circle Coordinates Java

Example

import java.awt.*;
import java.applet.*;
/* <applet code="DrawOvalEx.class" width=300 height=300>
</applet> */

public class DrawOvalEx extends Applet
{	
	public void paint(Graphics g)
	{
		g.drawOval(60, 60, 150, 150);
		g.fillOval(220, 60, 150, 150);
	}
}

Output

Applet Oval Circle Java

Oval

Ovals are like a rectangle with rounded corners. Oval does not have same width and height.

Applet Oval Example

Example

import java.awt.*;
import java.applet.*;
/* <applet code="DrawOvalEx.class" width=300 height=300>
</applet> */

public class DrawOvalEx extends Applet
{	
	public void paint(Graphics g)
	{
		g.fillOval(60, 60, 80, 100);
		g.fillOval(150, 60, 80, 100);
		g.drawOval(95, 170, 100, 50);
		g.drawOval(5, 90, 30, 100);
		g.drawOval(255, 90, 30, 100);
		g.drawOval(120, 250, 50, 50);
		
	}
}

Output

Draw Oval
<< Previous Next >>

See Also

All Java Programs
Java Keywords
Java Interview Questions

AndroidBerry Support

About us
Contact us
Suggest us
Questions?

Follow us

Androidberry FacebookFacebook
Androidberry TwitterTwitter
Androidberry GooglePlusGoogle+
Back to top
Androidberry Name Logo