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);
}
}
Showing posts with label Applet Code. Show all posts
Showing posts with label Applet Code. Show all posts
Subscribe to:
Posts (Atom)