aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Please check if the paint method used properly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Please check if the paint method used properly" Watch "Please check if the paint method used properly" New topic
Author

Please check if the paint method used properly

mayur khatri
Greenhorn

Joined: Aug 10, 2010
Posts: 10
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

Joined: Jul 26, 2007
Posts: 10384
    
    8

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
mayur khatri
Greenhorn

Joined: Aug 10, 2010
Posts: 10
Thanks rob it has helped.
Will ask for queries if i have any doubt.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Cross-posted: game-using-swings-not-working

Please read the FAQ regarding cross-posts: BeForthrightWhenCrossPostingToOtherSites

Thanks for your cooperation.
mayur khatri
Greenhorn

Joined: Aug 10, 2010
Posts: 10
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

Joined: Oct 13, 2005
Posts: 38888
    
  23
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.
 
jQuery in Action, 2nd edition
 
subject: Please check if the paint method used properly