AWT Graphics2D

Java 2D API -


The Java 2D API provides two-dimensional graphics, text, and imaging capabilities for Java programs through extensions to the Abstract Windowing Toolkit (AWT). Java.awt.geom package provides the Java 2D classes for defining and performing operations on objects related to two-dimensional geometry.

Working with Graphics2D class -

AWT provides Graphics2D class that extends Graphics class that provides more sophisticated control over geometry, coordinate transformations, color management, and text layout. This class is also used to draw 2D graphics provided by java.awt.geom package that we will learn next.

Graphics2D class has the following declaration -

      public abstract class Graphics2D extends Graphics
  

we can create objects of Graphics2D class by using Graphics class object as follows -
      Graphics2D graphics2dObjName = (Graphics2D) graphicsObject;
  

Graphics2D Methods-

Some important methods of Graphics2D are as follows -

1- draw() -

Used to draw the outline of a Shape using the settings of the current Graphics2D context.
It has the following syntax -
        public abstract void draw(Shape s)
    

2- fill() -

Fills the interior of a Shape using the settings of the Graphics2D context.
It has the following syntax -
        public abstract void fill(Shape s)
    

3- setStroke() -

Sets the Stroke for the Graphics2D context.
It has the following syntax -
        public abstract void setStroke(Stroke s)
    

4- translate() -

Translates the origin of the Graphics2D context to the point (x, y) in the current coordinate system.
It has the following syntax -
        public abstract void translate(int x, int y)
    

5- rotate() -

Concatenates the current Graphics2D Transform with a rotation transform. Subsequent rendering is rotated by the specified radians relative to the previous origin.
It has the following syntax -
        public abstract void rotate(double theta)
    

6- Draw3DRect() -

Draws a 3-D highlighted outline of the specified rectangle. The edges of the rectangle are highlighted so that they appear to be bevelled and lit from the upper left corner.
It has the following syntax -
        public void draw3DRect(int x,  int y,  int width, int height, boolean raised)
    

7- Fill3DRect() -

Paints a 3-D highlighted rectangle filled with the current color. The edges of the rectangle are highlighted so that it appears as if the edges were bevelled and lit from the upper left corner.
It has the following syntax -
        public void fill3DRect(int x, int y, int width, int height,  boolean raised)
    

Example -

import java.awt.*;
import java.applet.*;
public class Test extends Applet
{
    public void paint(Graphics g)
    {
        Graphics2D gd = (Graphics2D)g;
        BasicStroke bs = new BasicStroke(10.0f);
        gd.setStroke(bs);
        gd.drawRect(10,10,100,100);
        int width = getSize().width;
        int height = getSize().height;
        gd.translate(width/2, height/2);
        gd.drawRect(10,10,100,100);  
    }
}

Output -


Program Description -

                                                      
  • java.awt.BasicStroke class is used to set the shape and decoration of graphics objects outlines which are rendered with Graphics2D objects that has its Stroke attribute set to this BasicStroke.
    It has several constructors, the simplest one is as follows -
    public BasicStroke(float width) 
    Where width - the width of the BasicStroke
    It constructs a solid BasicStroke with the specified line width.
    
  • getSize() method returns the size of this(current component i.e Applet) component in the form of a Dimension object. It has the following syntax -
    public Dimension getSize()
    The java.awt.Dimension class encapsulates the width and height of a component (in integer precision) in a single object. We can get the width and height of current component (i.e. Applet) as follows -
    int width = getSize().width;
    int height = getSize().height;
    
    
  • translate(int x, int y ) available in java.awt.Graphics2D class translates the origin of the Graphics2D context to the point (x, y) in the current coordinate system. By default the origin is at top left corner of the applet, the following code will shift the origin to middle of applet window -
        gd.translate(width/2, height/2);
       

java.awt.geom Package -

Provides the Java 2D classes for defining and performing operations on objects related to two-dimensional geometry. Some popular classes of the package are as follows -


Line2D -

Used to draw a 2D line. It is an abstract class, so we cannot directly instantiated directly.
It has the following two sub classes -

  • Line2D.Double - It defines a line whose coordinates are defined by double data type parameters. It has the following constructors-
    Line2D.Double()
    It constructs and initializes a Line with coordinates (0, 0) to (0, 0).
    
    Line2D.Double(double x1, double y1, double x2, double y2)
    Constructs and initializes a Line2D from (x1, y1) to (x2, y2)coordinates.
    
  • Line2D.Float - It defines a line whose coordinates are defined by float data type parameters.
    It has the following constructors -
    Line2D.Float()
    Constructs and initializes a Line with coordinates (0, 0) to (0, 0).
    
    Line2D.Float(float x1, float y1, float x2, float y2)
    Constructs and initializes a Line from (x1, y1) to (x2, y2) coordinates.
    
        

Example -

import java.awt.*;
import java.applet.*;
import java.awt.geom.*;
public class Test extends Applet
{
    public void paint(Graphics g)
    {
        Graphics2D gd = (Graphics2D)g;
        Line2D ln1 = new Line2D.Float(50.0f,20.12f,200.13f,20.4f);
        Line2D ln2 = new Line2D.Double(70.5,40.5,200.4,40.5);
        gd.draw(ln1);
        gd.draw(ln2);
    }
}

Output -


Rectangle2D -

The Rectangle2D class describes a rectangle defined by a location (x,y) and dimension (width x height). It is an abstract class, so we cannot instantiated it directly.
It has two subclasses -

  • Rectangle2D.Double- The Double class defines a rectangle specified in double coordinates. It has the following constructors -
    Rectangle2D.Double()
    Constructs a new Rectangle2D, initialized to location (0, 0) and size (0, 0).
    
    Rectangle2D.Double(double x, double y, double width, double height)
    Constructs and initializes a Rectangle2D whose starting points are specified by (x, y) and width and height are 
    specified by width and height attributes.
    
  • Rectangle2D.Float - The Float class defines a rectangle specified in float coordinates. It has the following constructors -
    Rectangle2D.Float()
    Constructs a new Rectangle2D, initialized to location (0.0, 0.0) and size (0.0, 0.0).
    
    Rectangle2D.Float(float x, float y, float width, float height)
    Constructs and initializes a Rectangle2D whose starting points are specified by (x, y) and width and height are
    specified by width and height attributes.
    

Example -

import java.awt.*;
import java.applet.*;
import java.awt.geom.*;
public class Test extends Applet
{
    public void paint(Graphics g)
    {
        Graphics2D gd = (Graphics2D)g;
       Rectangle2D r1 = new Rectangle2D.Float(10.5f,10.5f,200.0f,100.0f);
       gd.draw(r1);  //or gd.fill(r1);
       Rectangle2D r2= new Rectangle2D.Double(50.55,50.55,200.00,100.00);
       gd.fill(r2);  //or gd.draw(r2);
       
    }
}

Output -


RoundRectangle2D -

The RoundRectangle2D class defines a rectangle with rounded corners defined by a location (x,y), a dimension (w x h), and the width and height of an arc with which to round the corners. It is an abstract class, so we cannot instantiated it directly.
It has two subclasses -

  • RoundRectangle2D.Double - The Double class defines a rectangle with rounded corners all specified in double coordinates. It has following 2 constructors -
    RoundRectangle2D.Double() 
    It constructs a new RoundRectangle2D, initialized to location (0.0, 0.0), size (0.0, 0.0), and corner arcs of 
    radius 0.0.
    
    RoundRectangle2D.Double(double x, double y, double w, double h, double arc_width, double arc_height) - 
    It constructs and initializes a RoundRectangle2D that starts from (x, y) , size (width, height), and corner arcs 
    of size (arc_width, arc_height).
    
  • RoundRectangle2D.Float - The Float class defines a rectangle with rounded corners all specified in float coordinates. It has following 2 constructors -
    RoundRectangle2D.Float()
    It constructs a new RoundRectangle2D, initialized to location (0.0, 0.0), size (0.0, 0.0), and corner arcs of 
    radius 0.0.
    
    RoundRectangle2D.Float(float x, float y, float width, float height, float arc_width, float arc_height)
    It constructs and initializes a RoundRectangle2D from the specified float coordinates.
     

Example -

import java.awt.*;
import java.applet.*;
import java.awt.geom.*;
public class Test extends Applet
{
    public void paint(Graphics g)
    {
        Graphics2D gd = (Graphics2D)g;
       RoundRectangle2D r1 = new RoundRectangle2D.Float(10.5f,10.5f,200.0f,100.0f, 30.5f, 40.5f);
       gd.draw(r1);  //or gd.fill(r1);
       RoundRectangle2D r2= new RoundRectangle2D.Double(50.55,50.55,200.00,100.00, 30.50, 40.50);
       gd.fill(r2);  //or gd.draw(r2);
       
    }
}

Output -


Ellipse2D -

The Ellipse2D class describes an ellipse that is defined by a framing rectangle. It is an abstract class, so we cannot instantiated it directly.
It has two subclasses -
  • Ellipse2D.Double- The Double class defines an ellipse specified in double precision. It has following 2 constructors -
    Ellipse2D.Double()- 
    It constructs a new Ellipse2D, initialized to location (0, 0) and size (0, 0).
    
    Ellipse2D.Double(double x, double y, double width, double height)- 
    It constructs and initializes an Ellipse2D within a rectangle whose starting points are (x, y) and width and height 
    is specified by (width, height).
    
  • Ellipse2D.Float - The Float class defines an ellipse specified in float precision. It has following 2 constructors -
    Ellipse2D.Float()- 
    It constructs a new Ellipse2D, initialized to location (0, 0) and size (0, 0).
    
    Ellipse2D.Float(float x, float y, float w, float h)-
    It constructs and initializes an Ellipse2D from the specified coordinates.    
    

Example -

import java.awt.*;
import java.applet.*;
import java.awt.geom.*;
public class Test extends Applet
{
    public void paint(Graphics g)
    {
        Graphics2D gd = (Graphics2D)g;
       Ellipse2D e1 = new Ellipse2D.Float(10.5f,10.5f,200.0f,100.0f);
       gd.draw(e1);  //or gd.fill(r1);
       Ellipse2D e2= new Ellipse2D.Double(50.55,50.55,200.00,100.00);
       gd.fill(e2);  //or gd.draw(r2);
       
    }
}

Output -


Arc2D -

It is similar to the arc we used previously with the additional option of defining arc closure type that can have one of the following values - OPEN, CHORD or PIE
These are the static integer fields have the following meanings -

  • static int OPEN - The closure type for an open arc with no path segments connecting the two ends of the arc segment.
    Example -
  • static int CHORD - The closure type for an arc closed by drawing a straight line segment from the start of the arc segment to the end of the arc segment.
    Example ?
  • static int PIE - The closure type for an arc closed by drawing straight line segments from the start of the arc segment to the centre of the full ellipse and from that point to the end of the arc segment.
    Example ?
Arc2D is an abstract class, so we cannot instantiated it directly.
It has two subclasses -
  • Arc2D.Double - This class defines an arc specified in double precision. It has following constructors -
    Arc2D.Double() - 
    It constructs a new OPEN arc, initialized to location (0, 0), size (0, 0), angular extents (start = 0, extent = 0).
    
    Arc2D.Double(double x, double y, double w, double h, double start, double extent, int type)- 
    It constructs a new arc, initialized to the specified location, size, angular extents, and closure type.
    Parameters - 
    x - The X coordinate of the upper-left corner of the arc's framing rectangle.
    y - The Y coordinate of the upper-left corner of the arc's framing rectangle.
    w - The overall width of the full ellipse of which this arc is a partial section.
    h - The overall height of the full ellipse of which this arc is a partial section.
    start - The starting angle of the arc in degrees.
    extent - The angular extent of the arc in degrees.
    type - The closure type for the arc: Arc2D.OPEN, Arc2D.CHORD, or Arc2D.PIE.
    
    
    Arc2D.Double(int type)-         
    It constructs a new arc, initialized to location (0, 0), size (0, 0), angular extents (start = 0, extent = 0), and 
    the specified closure type.
    Parameters - 
    type - The closure type for the arc: Arc2D.OPEN, Arc2D.CHORD, or Arc2D.PIE.    
    
    Arc2D.Double(Rectangle2D ellipseBounds, double start, double extent, int type) -
    It constructs a new arc, initialized to the specified location, size, angular extents, and closure type.
    Parameters - 
    ellipseBounds - The framing rectangle that defines the outer boundary of the full ellipse of which this arc
    is a partial section.
    start - The starting angle of the arc in degrees.
    extent - The angular extent of the arc in degrees.
    type - The closure type for the arc: Arc2D.OPEN, Arc2D.CHORD, or Arc2D.PIE.
    
    
  • Arc2D.Float - This class defines an arc specified in float precision. It has the following constructors -
    Arc2D.Float() - 
    It constructs a new OPEN arc, initialized to location (0, 0), size (0, 0), angular extents (start = 0, extent = 0).
    
    Arc2D.Float(float x, float y, float w, float h, float start, float extent, int type) - 
    It constructs a new arc, initialized to the specified location, size, angular extents, and closure type.     
    Parameters - 
    x - The X coordinate of the upper-left corner of the arc's framing rectangle.
    y - The Y coordinate of the upper-left corner of the arc's framing rectangle.
    w - The overall width of the full ellipse of which this arc is a partial section.
    h - The overall height of the full ellipse of which this arc is a partial section.
    start - The starting angle of the arc in degrees.
    extent - The angular extent of the arc in degrees.
    type - The closure type for the arc: Arc2D.OPEN, Arc2D.CHORD, or Arc2D.PIE.
    
    
    Arc2D.Float(int type) -
    It constructs a new arc, initialized to location (0, 0), size (0, 0), angular extents (start = 0, extent = 0), and 
    the specified closure type.
    Parameters - 
    type - The closure type for the arc: Arc2D.OPEN, Arc2D.CHORD, or Arc2D.PIE.
    
    Arc2D.Float(Rectangle2D ellipseBounds, float start, float extent, int type) - 
    It constructs a new arc, initialized to the specified location, size, angular extents, and closure type.
    Parameters - 
    ellipseBounds - The framing rectangle that defines the outer boundary of the full ellipse of which this arc is 
    a partial section.
    start - The starting angle of the arc in degrees.
    extent - The angular extent of the arc in degrees.
    type - The closure type for the arc: Arc2D.OPEN, Arc2D.CHORD, or Arc2D.PIE.
    
    

Example -

import java.awt.*;
import java.applet.*;
import java.awt.geom.*;
public class Test extends Applet
{
    public void paint(Graphics g)
    {
        Graphics2D gd = (Graphics2D)g;
       Arc2D a1 = new Arc2D.Double(10,10,100,100,90,90,Arc2D.OPEN);
       Arc2D a2 = new Arc2D.Double(50,50,100,100,90,90,Arc2D.CHORD);
       Arc2D a3 = new Arc2D.Double(80,80,100,100,90,90,Arc2D.PIE);
       gd.draw(a1);  // or gd.fill(a1);
       gd.draw(a2);  // or gd.fill(a2);
       gd.draw(a3);  // or gd.fill(a3);
    }
}
    

Output -


QuadCurve2D -

The CubicCurve2D class defines a cubic parametric curve segment in (x,y) coordinate space. It is an abstract class, so we cannot instantiated it directly.
It has two subclasses -

  • CubicCurve2D.Double - A cubic parametric curve segment specified with double coordinates. It has following constructors -
    CubicCurve2D.Double() - 
    It constructs and initializes a CubicCurve with coordinates (0, 0, 0, 0, 0, 0, 0, 0).
    
    CubicCurve2D.Double(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) -
    It constructs and initializes a CubicCurve2D from the specified double coordinates.
    Parameters - 
    x1 - the X coordinate for the start point of the resulting CubicCurve2D
    y1 - the Y coordinate for the start point of the resulting CubicCurve2D
    ctrlx1 - the X coordinate for the first control point of the resulting CubicCurve2D
    ctrly1 - the Y coordinate for the first control point of the resulting CubicCurve2D
    ctrlx2 - the X coordinate for the second control point of the resulting CubicCurve2D
    ctrly2 - the Y coordinate for the second control point of the resulting CubicCurve2D
    x2 - the X coordinate for the end point of the resulting CubicCurve2D
    y2 - the Y coordinate for the end point of the resulting CubicCurve2D
    
    
  • CubicCurve2D.Float - A cubic parametric curve segment specified with float coordinates. It has following constructors -
    CubicCurve2D.Float() -  
    It constructs and initializes a CubicCurve with coordinates (0, 0, 0, 0, 0, 0, 0, 0).
    
    CubicCurve2D.Float(float x1, float y1, float ctrlx1, float ctrly1, float ctrlx2, float ctrly2, float x2, float y2) - 
    It constructs and initializes a CubicCurve2D from the specified float coordinates.    
    Parameters - 
    x1 - the X coordinate for the start point of the resulting CubicCurve2D
    y1 - the Y coordinate for the start point of the resulting CubicCurve2D
    ctrlx1 - the X coordinate for the first control point of the resulting CubicCurve2D
    ctrly1 - the Y coordinate for the first control point of the resulting CubicCurve2D
    ctrlx2 - the X coordinate for the second control point of the resulting CubicCurve2D
    ctrly2 - the Y coordinate for the second control point of the resulting CubicCurve2D
    x2 - the X coordinate for the end point of the resulting CubicCurve2D
    y2 - the Y coordinate for the end point of the resulting CubicCurve2D
    
    

Example -

import java.awt.*;
import java.applet.*;
import java.awt.geom.*;
public class Test extends Applet
{
    public void paint(Graphics g)
    {
        Graphics2D gd = (Graphics2D)g;
       CubicCurve2D c1 = new CubicCurve2D.Double(200,100,100,150,300,250,200,300);
       gd.draw(c1);
    }
}
    

Output -


Program Description -
The above program draw a cubic cure that starts at the point (200, 100), whose first control points are at (100, 150), second control points are at (300, 250) and ending point of cure is at (200, 300).

Question -

Draw the following shape -

import java.awt.*;
import java.applet.*;
import java.awt.geom.*;
public class Test extends Applet
{
    public void paint(Graphics g)
    {
       Graphics2D gd = (Graphics2D)g;
       CubicCurve2D c1 = new CubicCurve2D.Double(200,100,250, 200,180, 250,200,350);
       CubicCurve2D c2 = new CubicCurve2D.Double(260,100,300, 200,210, 230,200,350);
       Line2D l1 = new Line2D.Double(200, 100, 230, 130);
       Line2D l2 = new Line2D.Double(260, 100, 230, 130);
       
       gd.draw(c1);
       gd.draw(c2);
       gd.draw(l1);
       gd.draw(l2);
    }
}
            
Using the classes and methods we learn till now, it is not possible to fill the above shape with any color. To fill such shapes java.awt.geom package contain a class named GeneralPath.

GeneralPath -

The GeneralPath class represents a geometric path constructed from straight lines, and quadratic and cubic (Bezier) curves. It can contain multiple sub paths.
It also inherits Path2D class. The Path2D classes provide full implementations of a general geometric path that support all of the functionality of the Shape and PathIterator interfaces with the ability to explicitly select different levels of internal coordinate precision. It has several constructors , the most commonly used is as follows -
GeneralPath() 
It constructs a new empty single precision GeneralPath object.
It inherits several methods from Path2D class. The most commonly used methods are as follows -
  • moveTo() -
  • This method is used to move to a particular place specified by (x, y) coordinates on Applets.
    There are two versions of moveTo() available one take double type parameters and another one take float type parameters. Here is the syntax -
    public final void moveTo(double x,  double y)
    Here coordinates of the path is specified in double data type.
    Parameters - 
    x - the specified X coordinate
    y - the specified Y coordinate
    
    
    public final void moveTo(float x,  float y)
    Here coordinates of the path is specified in double data type.
    Parameters - 
    x - the specified X coordinate
    y - the specified Y coordinate
    
    
  • lineTo() - This method is used to draw a line from current coordinates to the new specified coordinates specified in double precision.
    It also contains two versions one take double type parameters and another takes float type parameters.
    public final void lineTo(double x, double y)
    Adds a point to the path by drawing a straight line from the current coordinates to the new specified coordinates 
    specified in double precision.
    Parameters - 
    x - the specified X coordinate
    y - the specified Y coordinate
    
    
    public final void lineTo(float x,  float y)    
    Adds a point to the path by drawing a straight line from the current coordinates to the new specified coordinates specified in float precision.
    Parameters - 
    x - the specified X coordinate
    y - the specified Y coordinate
    
    
  • quadTo() - It is used to draw a quadratic curve that starts from the current coordinates and whose control points and end points are specified by parameters.
    It also contains two versions one take double type parameters and another takes float type parameters.
    public final void quadTo(double x1,  double y1,  double x2,  double y2) 
    Here parameters are specified by double data type.
    Parameters - 
    x1 - the X coordinate of the quadratic control point
    y1 - the Y coordinate of the quadratic control point
    x2 - the X coordinate of the final end point
    y2 - the Y coordinate of the final end point
    
    public final void quadTo(float x1, float y1, float x2,  float y2) 
    Here parameters are specified by float data type.
    Parameters -
    x1 - the X coordinate of the quadratic control point
    y1 - the Y coordinate of the quadratic control point
    x2 - the X coordinate of the final end point
    y2 - the Y coordinate of the final end point.
    
  • curveTo() - It is used to draw a cubic curve that starts from the current coordinates and whose both control points and end points are specified by parameters.
    It also contains two versions one take double type parameters and another takes float type parameters.
    public final void curveTo(double x1, double y1, double x2, double y2, double x3, double y3)
    Here parameters are specified by double data type.
    Parameters - 
    x1 - the X coordinate of the first Bézier control point
    y1 - the Y coordinate of the first Bézier control point
    x2 - the X coordinate of the second Bézier control point
    y2 - the Y coordinate of the second Bézier control point
    x3 - the X coordinate of the final end point
    y3 - the Y coordinate of the final end point
            
    
    public final void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
    Here parameters are specified by float data type.
    Parameters - 
    x1 - the X coordinate of the first Bézier control point
    y1 - the Y coordinate of the first Bézier control point
    x2 - the X coordinate of the second Bézier control point
    y2 - the Y coordinate of the second Bézier control point
    x3 - the X coordinate of the final end point
    y3 - the Y coordinate of the final end point
            
    

Example -

import java.awt.*;
import java.applet.*;
import java.awt.geom.*;
public class Test extends Applet
{
    public void paint(Graphics g)
    {
       Graphics2D gd = (Graphics2D)g;
       GeneralPath p1 = new GeneralPath();
       p1.moveTo(200,100);
       p1.curveTo(250, 200,180, 250,200,350);
       p1.curveTo(210, 230,300, 200,260,100);
       p1.lineTo(230, 130);
       p1.lineTo(200, 100);
       gd.setColor(Color.red);
       gd.fill(p1); 
    }
} 

Output -


Try the following examples -

1- Draw the following Chess Board using Applet -


import java.awt.*;
import java.applet.*;
public class Test extends Applet
{
    public void paint(Graphics g)
    {
       int width = getSize().width;
       int height = getSize().height;
       int cell_width = width/8;
       int cell_height = height/8;
       for(int i=0;i<8;i++)
       {
           for(int j=0; j<8;j++)
           {
               if((i+j)%2 == 0)
               {
                   g.setColor(Color.white);
               }
               else
               {
                   g.setColor(Color.black);
               }
               g.fillRect(j*cell_width, i*cell_height, cell_width, cell_height);
           }
       }
    }
}
    

2- Draw the following Snake Ladder board -

import java.awt.*;
import java.applet.*;
public class Test extends Applet
{
    public void paint(Graphics g)
    {
        int no = 100;
       int width = getSize().width;
       int height = getSize().height;
       /* A snake ladder board contains total 100 cells(10 rows, 10 columns)
       so one cell with and height will be total_width/10 and total_height/10 respectivly*/
       int cell_width = width/10;   
       int cell_height = height/10;
       for(int i=0;i<10;i++)
       {
           int t = 0;
           for(int j=0; j<10;j++)
           {
               int val = (i+j)%5;
               switch(val)   // for 5 different colors
               {
                   case 0:
                       g.setColor(Color.red);
                       break;
                   case 1:
                       g.setColor(Color.green);
                       break;
                   case 2:
                       g.setColor(Color.blue);
                       break;
                   case 3:
                       g.setColor(Color.yellow);
                       break;
                   case 4:
                       g.setColor(Color.white);
                       break;
               }
               g.fillRect(j*cell_width, i*cell_height, cell_width, cell_height);
               g.setColor(Color.black);  // cell number should be of black color.
                /* if an even row then cell number will be printed from left to right And if an odd row cell number will be printed right to left. We have concatenated a blank string with the cell number to convert that to string.     */
               if(i%2 == 0)
               {
                   g.drawString(no - t+" ", j*cell_width, (i+1)*cell_height);
               }
               else
               {
                  g.drawString((no - 9)+ t +" ", j*cell_width, (i+1)*cell_height); 
               }
               t++;
           }
           no = no -10;
       }
    }
}