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.

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!


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


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

Let us improve this post!

Tell us how we can improve this post?

Suryateja Pericherla

Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.

He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.

He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.

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 *