Problem with event hadling in fullscreen mode

I made a fullscreen application 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.

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);

}

}

[7534 byte] By [Japhetha] at [2007-11-26 14:08:07]
# 1

If you look above the list of topics in this forum you will see this message:

Thank you for any participation in this forum. Due to a lack of relevant activity, we have decided to archive this forum on June 16, 2006. For future posts on this topic, we suggest you use the Enterprise JavaBeans forum.

zadoka at 2007-7-8 1:54:36 > top of Java-index,Security,Event Handling...
# 2
Oops! I guess I'll repost and thanks for telling me.
Japhetha at 2007-7-8 1:54:36 > top of Java-index,Security,Event Handling...
# 3
> Oops! I guess I'll repost and thanks for telling me.That is fine, I didn't notice for a while too. Sun should prevent posting on "archived forums".Anyway put a link to your new post here, in case somewhere else stumbles about your question.
zadoka at 2007-7-8 1:54:36 > top of Java-index,Security,Event Handling...
# 4
I reposted this thread [url= http://forum.java.sun.com/thread.jspa?threadID=5121292]here[/url]
Japhetha at 2007-7-8 1:54:36 > top of Java-index,Security,Event Handling...