I have just released D-Zone II for PC and Mac OS X, actually the press releases go out next week but the game is ready for download. I had one minor problem that I wondered if anyone had experienced here. On Windows the game runs fine in 640x480 full screen, however on Mac OS X it succeeds in opening in 640x480 full screen and showing the game, however the application’s window is not in focus and so there is no keyboard and limited mouse interaction. I am thus releasing the Mac version with the game running in a little window for now, which is not great.
I looked at the API for the ‘Component’ class and found that you have to make sure the Component (I’m using JFrame but that doesn’t matter, it could be JWindow or even Window) has to be ‘displayable’, ‘focusable’ and ‘visible’ before it can be put in focus. You can enquire these three properties by calling isFocusable(), etc, as part of the Component API. What I was finding was that under both Windows and Mac OS X, these three properties were true! However, when I call ‘setFocus()’ the application still stayed out of focus for Mac OS X.
This appears to be a bug with the Mac OS X implementation of Java (I am using 1.4.2). Has anyone had any experience with this?
Best regards
Julian Cochran
PS: I have the code below that allows you to open the screen in 640x480 full screen. It works fine with PC AND ALSO under Mac OS X, however with Mac OS X it causes the application to be out of focus so there is no keyboard response - so receiving focus when running in full screen mode is essentially the problem.
I’d like to resolve this so that I can release D-Zone II for Java rather than making it a Windows-only game… (!!)
/**
- Changes the display mode and returns true if successful or false if not succesful.
- This method changes myWindow to full screen mode. The intention is that
- myWindow extends JWindow (rather than JFrame) so that no title bar is shown.
*/
public static DisplayMode setDisplayModeForDefaultDevice(Window myWindow, int x, int y, int bitDepth, int refreshRate) {
DisplayMode newDisplayMode = new DisplayMode(x, y, bitDepth, refreshRate);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice myDevice = ge.getDefaultScreenDevice();
DisplayMode oldDisplayMode = myDevice.getDisplayMode();
try {
myDevice.setFullScreenWindow(myWindow);
myDevice.setDisplayMode(newDisplayMode);
} catch (Exception e) {
return null;
}
return newDisplayMode;
// Ideally run the following when the application ends:
// myDevice.setDisplayMode(oldDisplayMode);
// myDevice.setFullScreenWindow(null);
}
Best regards
Julian