aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes how to implement the main() in the following code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to implement the main() in the following code?" Watch "how to implement the main() in the following code?" New topic
Author

how to implement the main() in the following code?

pandu chinnu
Greenhorn

Joined: Nov 21, 2006
Posts: 16
Hi there,

I was looking at this code in head first -



How do you implement the main method for this program?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
You'd do that by putting the JPanel inside of a JFrame. Here's an example of how that might work.


Ping & DNS - my free Android networking tools app
pandu chinnu
Greenhorn

Joined: Nov 21, 2006
Posts: 16
Hi,

I added the following main to the previous code



the program runs creating an Orange rectangle inside a frame,,,thanks. I had thought that it would work if we called the paintComponent() from within main. What is the reason that it dosen't work that way?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
You shouldn't call paintComponent directly - Swing does that for you.
 
 
subject: how to implement the main() in the following code?