You'll want to scrap this code and start over. For one, paintComponents is not the same as paintComponent, in fact there's a big difference. Next, you'll not want to read in images or do other file IO in a paintComponent method. Re-read the tutorials as they'll show the proper syntax. Best of luck and welcome to Java and the Ranch!
But in main() method, while creating an instance of ImagePanel(path), I'm writing path as "C:/Users/Pramod/Desktop/Beckham.jpg" , but its giving me nullpointer error.
I can't use '\' sign,
Please tell me how to write the correct path.