English 中文(简体)
未作出答复的滚动键盘
原标题:Swing keyboard not responding

I m using a KeyListener on a JFrame object which I set as FullScreenWindow, something like this code:

class Game{

private GraphicsDevice device;
...

public void run(){
JFrame frame = new JFrame();
frame.addKeyListener(new MarioKeyListener());
device.setFullScreenWindow(frame);
}

...
}

And it works fine if I just create a Game object in my main method and call run(). However I want to do this inside the mousePressed() function of a MouseAdapter which I added to another JFrame-s MenuItem. The result is that the program runs as normal but doesn t accept any keyboard input.

JMenu gamemenu = new JMenu("Game");
   JMenuItem newGame = new JMenuItem("New Game");
    newGame.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e){
    Game g = new Game();
    g.run();    
    }               
});
gamemenu.add(newGame);

I think My frame object is not in focus, but calling setFocusable(true) and requestfocusinwindow() did not help. If anyone knows whats wrong or how to fix this, help would be greatly appreciated...

Tomi

最佳回答

requestcusInWindow(/a>。

Requests that this Component get the input focus, if this Component s top-level ancestor is already the focused Window.

Are you checking the return value? I suspect it is failing because the new window is not the focused component at the moment the method is called.

如果情况是这样,答案可以与关于增加

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签