为什么这个JTextField没有显示内容?

时间:2014-12-30 02:05:00

标签: java jtextfield mouselistener

我正在尝试为我的游戏制作一个作弊代码按钮,并且显示它很好但我无法正确获取此文本字段的内容。这是它的代码:

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

的缩短版本

1 个答案:

答案 0 :(得分:1)

showInputDialog()方法返回用户输入的值。您应该将其捕获到变量中。例如,执行以下操作:

String userInputString = JOptionPane.showInputDialog("Enter Code Here");

变量userInputString将是一个包含您正在寻找的值的字符串。

相关问题