Suppose below is my code :

  public void paintComponent( Graphics g )
      graphics2D = (Graphics2D)g;
      graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      graphics2D.fillRect(0, 0, getSize().width, getSize().height);

and graphics2D is global variable declared like :

private Graphics2D graphics2D;

Now, how can I access g to draw lines from other methods?
When I'm accessing graphics2D, it's showing that NullPointerException.
and please also brief me about the Graphics g thing.

access g to draw lines from other methods

Call the other methods from the paint method and pass them the Graphics object: g that was passed to paint.