Java applet program to draw line and rectangle

Applet program to draw line and rectangle

This program illustrate the concept of applet program to draw line and rectangle.

  • Java graphics class includes methods for drawing many different shapes.
  • drawLine(x,y,a,b) is used to draw a line.
    1. (x,y) are the starting points of line.
    2. (a,b) are the ending point of line.
  • drawRect(x,y,a,b) is used to draw the rectangle.
    1. (x,y) are the coordinates of the top left corner of the rectangle.
    2. “a” is the width of rectangle
    3. “b” is the height of rectangle

Scanfcode.java

import java.awt.*;
import java.applet.*;
public class scanfcode extends Applet
{
	
  public void paint(Graphics g)
  {
	 
	  g.drawLine(40,50,200,10);
	  g.drawRect(30,70,90,40);
	  
  }
 
}

scanfcode.html

<html>
<head>
<title>
<p>First applet program</p>
</title>
</head>
<body>
<applet code="scanfcode.class" width="350" height="350">
</applet>
</body>
</html>

Command

Applet program to draw line and rectangle

OUTPUT

Applet program to draw line and rectangle


Comment below if you are facing any problem


Also Read

Java applet program to display numerical values
Java applet program to display textfields
Java program to display sum of two input numbers in applet


Summary
Java applet program to draw line and rectangle
Article Name
Java applet program to draw line and rectangle
Description
This program illustrate the concept of applet program to draw line and rectangle. Java graphics class includes methods for drawing many different shapes.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

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