Draw Shapes Using Java Applet

Here is the code of a simple program to draw shapes like rectangle, circle, line, etc using java applet. We need two classes to draw the shapes. Graphics method is used here to draw shapes. We are using drawingexample.class as class. See the example :

import java.applet.*;
import java.awt.*;
public class drawingexample extends Applet{
int x=300,y=100,r=50;
public void paint(Graphics g){
g.drawLine(3,300,200,10);
g.drawOval(x-r,y-r,100,100);
g.drawRect(400,50,200,100);
g.drawString("Circle",275,100);
g.drawString("Rectangle",450,100);
g.drawString("Line",100,100);

}

}





0 comments: