adsense


Monday, 2 November 2015

JAVA EXAMPLES CREATE DIFFERENT SHAPES IN AN APPLET PAGE 201

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES CREATE DIFFERENT SHAPES IN AN APPLET








Java Examples - Create different shapes in an Applet


Problem Description:
How to create different shapes using Applet?
Solution:
Following example demonstrates how to create an applet which will have a line, an Oval & a Rectangle using drawLine(), drawOval(, drawRect() methods of Graphics clas.
import java.applet.*;
import java.awt.*;

public class  Shapes extends Applet{
   int x=300,y=100,r=50;
   public void paint(Graphics g){
      g.drawLine(30,300,200,10);
      g.drawOval(x-r,y-r,100,100);
      g.drawRect(400,50,200,100);
   }
}
Result:
The above code sample will produce the following result in a java enabled web browser.
A line , Oval & a Rectangle will be drawn in the browser.


No comments: