找不到符号 event.getKeyCode()
Cannot find symbol event.getKeyCode()
我正在尝试将 KeyCode 转换为字符串,在阅读其他帮助后,.getKeyCode() 是将 KeyCode 转换为字符串的答案。但是在添加它之后,一个错误说它 "cannot find symbol" on .getKeyCode()。还有另一个 KeyEvent 导入,但如果使用该导入而不是我使用的当前导入,则错误消失但程序无法 运行.
这是我的控制器class:
package keyboardrecorder;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.input.KeyEvent;
public class Controller {
@FXML
private TextArea consoleKeyTyped;
private TextArea consoleKeyPressed;
private TextArea consoleKeyReleased;
public void outputKeyTyped(KeyEvent event) {
consoleKeyTyped.setText(consoleKeyTyped.getText() + event.getCharacter());
}
public void outputKeyPressed(KeyEvent event) {
consoleKeyPressed.setText(consoleKeyPressed.getText() + event.getKeyCode());
}
public void outputKeyReleased(KeyEvent event) {
}
}
这是我的 FXML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="keyboardrecorder.Controller">
<children>
<TabPane prefHeight="400.0" prefWidth="600.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab text="Key Typed">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<TextArea fx:id="consoleKeyTyped" editable="false" onKeyTyped="#outputKeyTyped" prefHeight="368.0" prefWidth="600.0" wrapText="true" />
</children>
</AnchorPane>
</content>
</Tab>
<Tab text="Key Pressed">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<TextArea fx:id="consoleKeyPressed" editable="false" onKeyPressed="#outputKeyPressed" prefHeight="368.0" prefWidth="600.0" wrapText="true" />
</children>
</AnchorPane>
</content>
</Tab>
<Tab text="Key Released">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<TextArea fx:id="consoleKeyReleased" editable="false" onKeyReleased="#outputKeyReleased" prefHeight="368.0" prefWidth="600.0" wrapText="true" />
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
</children>
</AnchorPane>
javafx.scene.input.KeyEvent is not java.awt.event.KeyEvent .
你想要 getCode()
而不是 getKeyCode()
。
我正在尝试将 KeyCode 转换为字符串,在阅读其他帮助后,.getKeyCode() 是将 KeyCode 转换为字符串的答案。但是在添加它之后,一个错误说它 "cannot find symbol" on .getKeyCode()。还有另一个 KeyEvent 导入,但如果使用该导入而不是我使用的当前导入,则错误消失但程序无法 运行.
这是我的控制器class:
package keyboardrecorder;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.input.KeyEvent;
public class Controller {
@FXML
private TextArea consoleKeyTyped;
private TextArea consoleKeyPressed;
private TextArea consoleKeyReleased;
public void outputKeyTyped(KeyEvent event) {
consoleKeyTyped.setText(consoleKeyTyped.getText() + event.getCharacter());
}
public void outputKeyPressed(KeyEvent event) {
consoleKeyPressed.setText(consoleKeyPressed.getText() + event.getKeyCode());
}
public void outputKeyReleased(KeyEvent event) {
}
}
这是我的 FXML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="keyboardrecorder.Controller">
<children>
<TabPane prefHeight="400.0" prefWidth="600.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab text="Key Typed">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<TextArea fx:id="consoleKeyTyped" editable="false" onKeyTyped="#outputKeyTyped" prefHeight="368.0" prefWidth="600.0" wrapText="true" />
</children>
</AnchorPane>
</content>
</Tab>
<Tab text="Key Pressed">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<TextArea fx:id="consoleKeyPressed" editable="false" onKeyPressed="#outputKeyPressed" prefHeight="368.0" prefWidth="600.0" wrapText="true" />
</children>
</AnchorPane>
</content>
</Tab>
<Tab text="Key Released">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<TextArea fx:id="consoleKeyReleased" editable="false" onKeyReleased="#outputKeyReleased" prefHeight="368.0" prefWidth="600.0" wrapText="true" />
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
</children>
</AnchorPane>
javafx.scene.input.KeyEvent is not java.awt.event.KeyEvent .
你想要 getCode()
而不是 getKeyCode()
。