Java application event help?

Discussion in 'Mac Programming' started by Awesomeness, Jan 31, 2010.

  1. Awesomeness macrumors member

    Joined:
    Feb 12, 2009
    #1
    In application events, how do I detect when my application receives focus? As in its menu is in the top left corner?
     
  2. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #2
    A little browsing of the API does you a lot of good. More specifically, you need to implement WindowFocusListener in your event handler class. This interface lives in java.awt.event, and contains 2 methods: void windowGainedFocus(WindowEvent) and void windowLostFocus(WindowEvent).
     
  3. Awesomeness thread starter macrumors member

    Joined:
    Feb 12, 2009
    #3
    I knew about that, but I didn't think it would work because sometimes all of the windows of my application will be hidden. I want it to show the hidden windows when my application gains focus.
     
  4. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #4
    Do you have an offscreen window, to handle the case when all windows are closed but the application should remain open, on the Mac OS? If you do, then attach the handler to that offscreen window.
     
  5. Awesomeness thread starter macrumors member

    Joined:
    Feb 12, 2009
    #5
    I know, that's my problem... I've tried setting the location to negative and way positive, but Macs won't let you put the window offscreen. Is there some other method to get windows offscreen, or is it something else entirely, like a virtual window? I've looked through the API for an hour and found nothing... :(
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #6
    Post your code. It should be enough code that someone else can compile and run it, not simply excerpts of what you think is relevant.
     

Share This Page