我正在尝试为我的游戏制作一个作弊代码按钮,并且显示它很好但我无法正确获取此文本字段的内容。这是它的代码:
cheats.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
Class.console("DISPLAYED OPTIONPANE");
JOptionPane.showInputDialog(cheatCode, "Enter Code Here");
Class.console("GOT STRING" + cheatCode.getText());
if(cheatCode.getText().equals("testin")) {
Class.console("testout");
}
}
我几乎是初学者,所以请帮忙吗?如果需要,我可以发布其他所有内容。
P.S。 Class.console()是我的驱动程序类中的一个东西。它基本上是System.out.println()
的缩短版本答案 0 :(得分:1)
showInputDialog()
方法返回用户输入的值。您应该将其捕获到变量中。例如,执行以下操作:
String userInputString = JOptionPane.showInputDialog("Enter Code Here");
变量userInputString
将是一个包含您正在寻找的值的字符串。