Startertutorials Blog
Tutorials and articles related to programming, computer science, technology and others.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.
Home » Programming » Java » Programs » Applets » Applet program to draw lines, ovals, and rectangles
Suryateja Pericherla Categories: Applets. 2 Comments on Applet program to draw lines, ovals, and rectangles
3
(16)

In this article we will implement an Applet program to draw a line, oval and rectangle. An Applet program is provided below to draw lines, ovals, and rectangles.

 

import java.applet.*;
import java.awt.*;
public class GApplet extends Applet
{
	public void paint(Graphics g)
	{
		g.drawLine(20, 20, 500, 20);
		g.drawRect(20, 40, 200, 40);
		g.fillRect(300, 40, 200, 40);
		g.drawRoundRect(20, 100, 200, 40, 10, 10);
		g.fillRoundRect(300, 100, 200, 40, 10, 10);
		g.setColor(Color.RED);
		g.drawOval(20, 160, 200, 100);
		g.fillOval(300, 160, 200, 100);
	}
}
/*
<applet code="GApplet" height="500" width="700" border="1">
</applet>
*/

 

Output for the above program is as follows:

applet-graphic-shapes

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?


Subscribe to our monthly newsletter. Get notified about latest articles, offers and contests.


2 Comments

You can follow any responses to this entry through the RSS 2.0 feed.

Why we using the value (20,20,500,20) instead of this value we can use any other values or not….

    Hi, a line has two end points. Let them be (x1, y1) and (x2, y2). Here (20,20,500,20) means (x1,y1,x2,y2). Off course they can be changed to whatever values you want.

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
Twitter
Pinterest
Youtube
Instagram
Blogarama - Blog Directory