This Java example shows how to draw a rectangle in Applet.
Graphics class in java.awt package provides various methods to draw different shapes like rectangle, line, polygon, oval, arc, etc.
Applet is a Java program that can be embedded into a web page. It runs inside the web browser and works at client side.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/* <applet code="DrawRectanglesExample" width=200 height=200> </applet> */ import java.applet.Applet; import java.awt.Graphics; public class DrawRectanglesExample extends Applet { public void paint(Graphics g) { //this will draw a rectangle of width 50 & height 100 at (10,10) g.drawRect(10,10,50,100); //this will draw a square g.drawRect(100,100,50,50); } } |