Java Graphics in Applet

Graphics operations can be performed using java.awt package that contains various classes and methods for creating graphics and images.The paint() takes graphic object as an argument and provides reference to graphics drawing methods(setColor(),drawstring()).


import java.awt.*;

import java.applet.*;

public class DrawExampl extends Applet


   Font bigFontt;

     Color redColoor;

     Color weirdColoor;

     Color bgColoor;

     public void init()


         bigFontt = new Font("Arial",Font.BOLD/Font.ITALIC,26);

          redColoor =;

          weirdColoor = new Color(60,60,122);

            bgColoor =;



     public void stop()



     public void paint(Graphics gra_ph)


     gra_ph.setFont(bigFontt); //setting the font

     gra_ph.setColor(Color.gray); //set the colours for drawing

     gra_ph.drawString("Different Shapes and Colors Graphics ",80,50);


     gra_ph.drawRect(100,100,100,100); //draw a hollow rectangle

   gra_ph.fillRect(110,110,80,80); //draw a filled rectangle


   gra_ph.fillArc(120,120,60,60,0,360);   //draw a filled arc


     gra_ph.drawLine(140,140,160,160); //draw a straight line




/*<applet code="DrawExample.class" height=500 width=500></applet>*/

 Graphics in Applet


The String value can be displayed using drawstring() method of the Graphics class.

Graphics are drawn on the window at the specified screen coordinates(measured in pixels)

clearRect(),drawLine(),drawArc(),drawOval(),drawPolygon(),fillArc(),setFont(),setColor() are drawing methods of the Graphics Class.