• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please check if the paint method used properly

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).

 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks rob it has helped.
Will ask for queries if i have any doubt.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic