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:
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.
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.