• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
pandu chinnu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I was looking at this code in head first -



How do you implement the main method for this program?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd do that by putting the JPanel inside of a JFrame. Here's an example of how that might work.
 
pandu chinnu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't call paintComponent directly - Swing does that for you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic