problem responding to events in fullscreen mode

I made a fullscreen game and I'm trying to get it to respond to the mouse or keyboard input. The problem is it only responds a few second after I press the button. Does anyone know how I could speed up the response? All my code is posted below.

EDIT: I did some experimenting and it looks like device.isDisplayChangeSupported() returns false and the resolution never gets changed to 800x600 (I haden't noticed this before since I was flooding the whole screen with black). I also took a look at the resolutions I could manually set the monitor to and it only shows 1280x800 and 1024x768. This is under Ubuntu Linux. Even though I haven't run this program under my Windows installation, I'm sure I can change to 800x600 resolution there since I've done it manually and through other programs. Does anybody know any solutions to this? I will probably try running the program under Windows and see what happens.

import java.awt.*;

import java.awt.event.*;

import java.awt.image.BufferStrategy;

publicclass LostHavenimplements KeyListener, MouseListener

{

privatestatic DisplayMode[] BEST_DISPLAY_MODES =new DisplayMode[]{

new DisplayMode(800, 600, 32, 0),

new DisplayMode(800, 600, 16, 0),

new DisplayMode(800, 600, 8, 0)

};

Frame mainFrame;

boolean done;

boolean pressed;

public LostHaven(GraphicsDevice device)

{

try

{

GraphicsConfiguration gc = device.getDefaultConfiguration();

mainFrame =new Frame(gc);

mainFrame.setUndecorated(true);

mainFrame.setIgnoreRepaint(true);

device.setFullScreenWindow(mainFrame);

if (device.isDisplayChangeSupported())

{

chooseBestDisplayMode(device);

}

mainFrame.addMouseListener(this);

mainFrame.addKeyListener(this);

mainFrame.createBufferStrategy(2);

BufferStrategy bufferStrategy = mainFrame.getBufferStrategy();

done =false;

pressed =false;

while (!done)

{

Graphics g = bufferStrategy.getDrawGraphics();

render(g);

g.dispose();

bufferStrategy.show();

}

}

catch (Exception e)

{

e.printStackTrace();

}

finally

{

device.setFullScreenWindow(null);

}

}

privatevoid render(Graphics g)

{

Rectangle bounds = mainFrame.getBounds();

g.setColor(Color.black);

g.fillRect(0,0,bounds.width, bounds.height);

g.setColor(Color.red);

g.fillRect(bounds.width*1/4, bounds.height*1/4, bounds.width*2/4, bounds.height*2/4);

if(pressed)

g.drawString("mouse pressed", 0, 15);

}

privatestatic DisplayMode getBestDisplayMode(GraphicsDevice device)

{

for (int x = 0; x < BEST_DISPLAY_MODES.length; x++)

{

DisplayMode[] modes = device.getDisplayModes();

for (int i = 0; i < modes.length; i++)

{

if (modes[i].getWidth() == BEST_DISPLAY_MODES[x].getWidth()

&& modes[i].getHeight() == BEST_DISPLAY_MODES[x].getHeight()

&& modes[i].getBitDepth() == BEST_DISPLAY_MODES[x].getBitDepth()

)

{

return BEST_DISPLAY_MODES[x];

}

}

}

returnnull;

}

publicstaticvoid chooseBestDisplayMode(GraphicsDevice device)

{

DisplayMode best = getBestDisplayMode(device);

if (best !=null)

{

device.setDisplayMode(best);

}

}

publicvoid mousePressed(MouseEvent e)

{

pressed =true;

}

publicvoid mouseReleased(MouseEvent e)

{

}

publicvoid mouseEntered(MouseEvent e)

{

}

publicvoid mouseExited(MouseEvent e)

{

}

publicvoid mouseClicked(MouseEvent e)

{

}

publicvoid keyTyped(KeyEvent e)

{

}

publicvoid keyPressed(KeyEvent e)

{

if(e.getKeyCode() == KeyEvent.VK_ESCAPE)

{

done =true;

}

}

publicvoid keyReleased(KeyEvent e)

{

}

publicstaticvoid main(String[] args)

{

try

{

GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();

GraphicsDevice device = env.getDefaultScreenDevice();

LostHaven gameWindow =new LostHaven(device);

}

catch (Exception e)

{

e.printStackTrace();

}

System.exit(0);

}

}

Message was edited by:

Japheth

[8245 byte] By [Japhetha] at [2007-11-26 14:08:12]
# 1
Do you get this behavior when it's not fullscreen (and the rest is the same)?
CaptainMorgan08a at 2007-7-8 1:54:43 > top of Java-index,Other Topics,Java Game Development...