hi ImDinesh,
as you can read, making a Swing application according to the rules is not an easy thing! It takes knowledge, experience, time and much practising.
As Rob pointed out, reading the tutorials and playing around with the examples given is a big part of the learning process. And as Campbell and Carey remarked,
you should use as the first line of your 'paintComponent(Graphics g)' the line: super.paintComponent(g). To help you making the learning process a tad easier, I've written a simple version of how you could set up your MyDrawPanel-program.
But first: why all the critique, given that your latest code does run flawlessly? To address two of them:
Your code does not run from the EDT
Indeed, it does not, yet it should. But it works nevertheless? Two years long, since I myself started to learn and use Swing, I had my code just like you have it. I started my Frames from the 'main' method, without any further ado, and it worked! And more, this was the code I read from some tutorials. But then came a man here at this site, who explained why it was wrong what we did. I will try to find a link to his writings, it is a couple of years ago. Now, at that time I didn't understand much of what the man told us, but it sure sounded mighty convincing!
You do not use 'super.paintComponent(g)'!
Indeed, you do not invoke that method. But believe me or not, in this case it is not necessary and can be left out! All that 'super.paintComponent(g)' does is clearing the panel and filling it completely with the background of the panel (you do not specify a background, so the default is used). Then your own user drawings are executed (in your case drawing the orange rectangle). Since from one update of the panel to another update of the panel nothing changes, you can indeed do without the clearing of the panel to its background color.
When you do, say, animations in your panel, then it is indeed necessary to clear the contents before drawing the next animation, for if you don't, you will see that these old drawings remain visible.
As said, this is not applicable to your MyDrawPanel and so you get away with it. But make it a habit of using this line of code, necessary or not.
Well, now for the code that I talked about. It shows one of the possibilities, but there are sure more ways to do this.