Search

Tuesday, November 11, 2014
0 comments

How to draw rectangle in applet

7:56 AMTuesday, November 11, 2014
Four coordinate are required For drawing the rectangle in the java applet. First two coordinate define the origin point of the rectangle. Origin point start from upper left corner and further x-coordinate increases width of the rectangle in right side and y-coordinate increases height of the rectangle in downward.

Syntax of drawRect in Java Applet

Graphics_Instance . drawRect(int X1, Int Y1, int Width, int Height);

If you want to set border color of the rectangle then use setColor( ) method of Graphics class, which is exist in java.awt package.

Example - designline.java

import java.awt.*;
import java.applet.*;
public class designline extends Applet
{
int width, height;

   public void init() {
   
      setBackground( Color.gray);
   }

   public void paint( Graphics g ) {

   

      g.setColor( Color.red );
      g.drawRect( 11, 22, 101, 50 );
}
}
First to compile the code and create the class file for this
First to compile the code and create the class file for this
Prepare the HTML file in the same location with <applet> tag. Like

<applet code="designline" width="400" height="400" />

Save the .html file in same location also run in any browser.

How to draw rectangle in applet
Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top