Refreshing the Applet

I am writing an applet for a game, and I'm changing the background color of buttons throughout the game (I'm using them as my game squares).  But, when I change the background color, the screen or button doesn't refresh the colors until the mouse passes over that button.  How can I force a refresh draw so that when i change the color of a button (background) it changes without the user having to pass the mouse over that button?

Laminamia
LVL 3
Laminamia063099Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbormannCommented:
in the event handler where u change color call paint() i think at end.
i am just guessing
0
Ravindra76Commented:
Yaa. Its only
0
Laminamia063099Author Commented:
Thanks, I'll try it out.

laminamia :)
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

mbormannCommented:
Oki fenokee,
just blaberring along
:-)
0
JodCommented:
Nearly, mb.

In the eventhandler you will need to invoke repaint() not paint(), because paint requires you to pass in the Graphics object for the component (in this case your button), like this:

paint(Graphics g)

whereas repaint you can just invoke, like this:

repaint();

For example, in an eventhandler you can do this:

  // store previous value on entering field
  public void focusGained( FocusEvent evt ) {
    Component c = evt.getComponent();
    if ( c instanceof Button ) {
      c.repaint()
    }
  }

or if it is just a method you are using to change the colour, then you need to provide the button component as a parameter, eg:

  // store previous value on entering field
  public void changeButtonColour( Button b ) {
      //change button colour to however you wish
        b.repaint();
  }

remember that repaint() only REQUESTS that the button be repainted. It may not happen straight away if the Applet is really busy.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mbormannCommented:
ok Jod,
see this site
http://members.tripod.com/gsraj/new.html

this has a unfinished one on Design Patterns which we gotta fill up as time goes by.

this is what i thought abt.
0
JodCommented:
Lots of good links on that site.

Which bit do you mean to fill up? Looks quite full...

Is it your site by the way, or someone you know?
0
mbormannCommented:
0
mbormannCommented:
Jod ?
0
JodCommented:
Yep still here. Do you mean to write up the blank ones?
0
mbormannCommented:
no time man,will now be involved in a major ba... after 10-15 days or so for the next 2/3 (?) months.

Anyway that is my dream.
and thanks for the other one,unowhatimean?sorry for bothering u.
See you old chap.

Hey u read any of Jack Higgins novel's ? I liked that chappie ,Liam Devlin ,he used to say "A Hundred Thousand Welcomes" in Irish?
what is it after translation?

Is that a fact
God bless all here
0
JodCommented:
Cead Mile Failte...
0
mbormannCommented:
thanks a millyun
0
mbormannCommented:
didja read abt him?
0
mbormannCommented:
wishful thinking on my part,new work arrived today ...so my holiday looks all set to be over.

Jod,
i worked mostly with IO,threads ,scokets etc... for abt 9 mths.Now am in GUI side.

we gotta convert all current code from a old version to a current one plus add some screens.

can u tell me what i gotta take care of?any URL's ?

thanks
BTW i learnt some RMI basics ,thanks for that and learnt something abt EJB.
0
JodCommented:
Cead Mile Failte...
0
mbormannCommented:
Oki fenokee
:-)
0
JodCommented:
There are lots of issues and lots of bugs, but generally Swing is better. for a start, look here for some stuff I wrote on Swing performance:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=10217416 



0
JodCommented:
Didn't mean to say that twice...

Two hundred thousand welcomes is a bit much.
0
mbormannCommented:
thanks seen it with a new light as i talked there before and had forgotten abt it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.