gpt4 book ai didi

带有关于 CGSEventRecord 的消息的 Java Key Listener Error

转载 作者:行者123 更新时间:2023-11-30 07:45:21 24 4
gpt4 key购买 nike

我正在学习使用 java 制作游戏并尝试实现 java.awt.event.KeyAdapter 以进行键盘输入。我的代码工作正常,除了当我使用一个键时,它给了我我想要的,但在控制台中抛出了一个巨大的错误。我对为什么会收到此错误感到困惑,我正在关注一些有关如何进行按键输入的文档,但并未提及此问题的发生。如何让我的控制台在每次按下按键时都不会抛出此错误?

KeyInput 类:

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class KeyInput extends KeyAdapter {

@Override
public void keyPressed(KeyEvent event) {
int key = event.getKeyCode();

System.out.println(key);
}

@Override
public void keyReleased(KeyEvent event) {

}
}

然后在我的主程序中,我编写了这段代码让我的游戏监听被按下的键

this.addKeyListener(new KeyInput());

这应该会返回每个键的 ID,确实如此。但是,控制台返回此错误以及正确的 ID。

2018-08-12 12:32:03.635 java[58065:6573813] -_cgsEventRecord is deprecated for _cgsEventRecord. Please use -CGEvent.
2018-08-12 12:32:03.635 java[58065:6573813] *** Assertion failure in -[NSEvent _cgsEventRecord], /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.40.112/AppKit.subproj/NSEvent.m:1972
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Non-Java exception raised, not handled! (Original problem: Deprecated in 10_12... DO NOT EVER USE CGSEventRecord directly. Bad things, man.... bad things.)
at apple.awt.ComponentModel._handleEvent(Native Method)
at apple.awt.ComponentModel.handleEvent(ComponentModel.java:273)
at apple.awt.CWindow.handleEvent(CWindow.java:545)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:753)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1000)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:865)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:686)
at java.awt.Component.dispatchEventImpl(Component.java:4648)
at java.awt.Container.dispatchEventImpl(Container.java:2142)
at java.awt.Window.dispatchEventImpl(Window.java:2492)
at java.awt.Component.dispatchEvent(Component.java:4604)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:717)
at java.awt.EventQueue.access$400(EventQueue.java:82)
at java.awt.EventQueue$2.run(EventQueue.java:676)
at java.awt.EventQueue$2.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:690)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:687)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

最佳答案

看来您使用的是 Java 6,应该升级到 Java 8。

我从消息中得到了那个指针

Non-Java exception raised, not handled! (Original problem: Deprecated in 10_12... DO NOT EVER USE CGSEventRecord directly. Bad things, man.... bad things.

关于带有关于 CGSEventRecord 的消息的 Java Key Listener Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51811360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com