Thursday, 22 January 2015

How to draw a lines in applet.


The awt supports a rich of graphics methods.All graphics are drawn relative to a window all output to a window takes place through a graphic context is encapsulated by the GRAPHICS class it is obtained by two ways


  • It is passed to an applet when one of its various methods,such as paint(). 
  • It's returned by the getGraphics() method of component.

DRAWLINE METHOD IN JAVA:

Lines are drawn in java by drawLine method,shown below

void drawLine(int startX,int startY,int endX,int endY)
drawLine() display a line in the current drawing color that begins at starX,startsY and endsX,endsY.

HTML CODE:

<html>
<body>
<applet code="lineapp" width="300" height="300">
</applet>
</body>
</html>

JAVA CODING:

import java.applet.*;
import java.awt.*;
public class lineapp extends Applet
{

public void paint(Graphics g){
g.drawLine(10,10,300,10);
g.drawLine(300,10,300,300);
g.drawLine(300,300,10,300);
g.drawLine(10,300,10,10);
}

}

OUTPUT:




No comments:

Post a Comment