I don't think the problem is related to the Applet not having focus in the browser window.
Based on the the keyPressed() method, I assume you are using a KeyListener that you've added to the JButton instance, correct?
That mechanism only works if the Jbutton has focus. You should have a look at the the tutorial on How to Use Key Bindings.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Every plan is a little cooler if you have a blimp. And a tiny ad.
Devious Experiments for a Truly Passive Greenhouse!