Java JLabel中的JButton显示文本

Java JLabel中的JButton显示文本,java,swing,jbutton,jlabel,Java,Swing,Jbutton,Jlabel,我开发了一个游戏 在我的第一个按钮中,我写了一个单词。在第二个按钮中,我输入一个字母 我想找到我用第一个按钮注册的单词。我的问题是,我不能支持我以前已经做过的研究 我不知道我能做什么,所以也许你能帮我,那太好了!对不起,我迟到了 例如: 如果我用我的第一个按钮写一个单词:“你好”,我的程序返回_ __ 如果我用第二个按钮搜索“h”,程序返回:h\uu\_ //用我的名义 但是现在,如果我搜索“e”,程序返回“e”,那么“h”不是 转载 我的代码,第一个Jbutton: ControllerPen

我开发了一个游戏

在我的第一个按钮中,我写了一个单词。在第二个按钮中,我输入一个字母

我想找到我用第一个按钮注册的单词。我的问题是,我不能支持我以前已经做过的研究

我不知道我能做什么,所以也许你能帮我,那太好了!对不起,我迟到了

例如:

如果我用我的第一个按钮写一个单词:“你好”,我的程序返回_ __

如果我用第二个按钮搜索“h”,程序返回:h\uu\_ //用我的名义

但是现在,如果我搜索“e”,程序返回“e”,那么“h”不是 转载

我的代码,第一个Jbutton:

ControllerPendu a = new ControllerPendu();
final JFrame popup = new JFrame();
this.word = JOptionPane.showInputDialog(popup, "Enter one word", null);

//control lenght of word, if the word < = 3 
String afterCtrl = a.controleW(word);


labelWord.setText("");
for (int i = 0; i < afterCtrl.length(); i++) {
    labelWord.setText(labelWord.getText() + "_ ");
    labelWord.validate();
    labelCompteur.repaint();
}

//counter key on the word, panel top/right
String mot = this.word;
labelCompteur.setText(String.valueOf(mot.length()));
ControllerPendu a=新的ControllerPendu();
最终JFrame弹出窗口=新JFrame();
this.word=JOptionPane.showInputDialog(弹出“输入一个单词”,null);
//如果单词<=3,则控制单词长度
Ctrl=a.controleW(word)后的字符串;
labelWord.setText(“”);
对于(int i=0;i
第二个按钮:

ControllerPendu a = new ControllerPendu();

final JFrame popup = new JFrame();
this.key = JOptionPane.showInputDialog(popup, "Enter one key", null);

char ctrlKey = a.controleK(key).charAt(0);     
// loop for print key of the word
for (int i = 0; i < this.word.length(); i++) {

    //retourn the key in function to the index 
    char lettre = word.charAt(i);


    if (ctrlKey == lettre) {
        labelWord.setText(key);

    } else  {
        labelWord.setText(labelWord.getText() + "_ ");

    }
}

    } else  {
        //is the ke isn't match, display "_ " 
        labelWord.setText(labelWord.getText() + "_ ");

    }
}
ControllerPendu a=新的ControllerPendu();
最终JFrame弹出窗口=新JFrame();
this.key=JOptionPane.showInputDialog(弹出“输入一个键”,null);
字符ctrlKey=a.controleK(键)。字符(0);
//循环用于打印单词的关键字
for(int i=0;i

ControllerPendu是一个检查单词和字母ctrlKey=第二个jButton中倾斜的键的类,为什么不将搜索结果存储在某个实例变量
字符串搜索结果
,然后每次有新的搜索时都可以更新它


抱歉,我希望我能发布如何做到这一点,但您的代码缺少一些部分,无法对您已经转发的内容进行粗略猜测。

您为什么要问这个问题?对于我的最后一个问题,但更全面的是,您应该编辑该问题,而不是问一个新问题。但是。。。我不知道如何保存labelWord.setText(键):(