Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please check if the paint method used properly

 
mayur khatri
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I all.I have started developing a ball breaker game using swings and i am posting the code for the same.
I am not able to move the user controlled base used for avoiding the ball from falling(controlling is to be done using the arrow keys i.e
left and right)

Please check if there is any error in calling the "paint" method and please suggest any changes if to be done.
Thanks in advance.

THE CODE :
-----------------------------------------------------------------------------------------------------
OuterFrame.java


-------------------------------------------------------------------------------
Wall.java

------------------------------------------------------------------------------------------
BaseBoard.java

The output which i am getting is just the ball and the baseboard painted inside the frame but there is no movement
when ever i press the keyboard arrow keys(left arrow key and right arrow key).

 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In future, while posting code, please UseCodeTags
I have edited your original post to incorporate them. As you can see, your code is now much more readable, and easier to understand.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Swing it's preferred to override paintComponent, not paint. The reason is because paint calls paintComponent but also makes sure any nested components are painted. If you override paint you will paint over everything. Check out the following example:
Run it. Then comment out the paint method and uncomment the paintComponent method. Run it again. You'll see the difference.
 
mayur khatri
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks rob it has helped.
Will ask for queries if i have any doubt.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cross-posted: game-using-swings-not-working

Please read the FAQ regarding cross-posts: BeForthrightWhenCrossPostingToOtherSites

Thanks for your cooperation.
 
mayur khatri
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pete stein wrote:Cross-posted: game-using-swings-not-working

Please read the FAQ regarding cross-posts: BeForthrightWhenCrossPostingToOtherSites

Thanks for your cooperation.


Read your guideline.Will follow them.
 
Campbell Ritchie
Sheriff
Posts: 48454
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mayur khatri wrote: . . . Read your guideline.Will follow them.
Also, please post a link to this discussion on the other site; everybody needs to know there are two discussions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic