• Post Reply Bookmark Topic Watch Topic
  • New Topic

Paint example not painting  RSS feed

 
Zeke Hans
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Hello,

I was trying to make a paint program on here, but it was not cooperating with me. I copied this code from Deitel's Java for Programmers book, and it came up, but would not let me paint. What am I doing wrong? Thanks!
 
Rob Camick
Ranch Hand
Posts: 2788
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


First you add the paint panel to the "CENTER" of the BorderLayout. Then you add the label to the "CENTER" as well. That is if you don't specify a constraint the BorderLayout assumes "CENTER". You can only have a single component in the CENTER so the label replaces the paint panel. Try:





 
Zeke Hans
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:

First you add the paint panel to the "CENTER" of the BorderLayout. Then you add the label to the "CENTER" as well. That is if you don't specify a constraint the BorderLayout assumes "CENTER". You can only have a single component in the CENTER so the label replaces the paint panel. Try:







Tried putting a SOUTH on the one, still would not work at all. According to my book, this code should allow you to draw. I am using windows 8. Could that affect things? Thanks!
 
Rob Camick
Ranch Hand
Posts: 2788
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take some time to learn Java standards:

1. Class names START with an upper case character on every word. "painttest" should be "PaintTest".
2. Method names DO NOT start with an upper case character. "MouseDragged" should be "mouseDragged".

A good practice when overriding a method is to use:



In case you make a typing error like you did, the compiler will warn you and tell you that the method does not override an existing method.
 
Zeke Hans
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




These are the actual code from the book. They look identical to me. They results are different though. It seems to me if there were any abstract classes that needed implemented, they would throw an error.
 
Rob Camick
Ranch Hand
Posts: 2788
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure why you posted the code from the book. I told you what the problems are with your code. When I fixed the problems the code ran fine for me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!