我的问题是,使用此代码,我的彩色图像没有显示。

时间:2019-07-04 00:21:20

标签: image jlabel show

我正在为幼儿园创建一个游戏,孩子们可以看到一种颜色并单击一个按钮来回答问题。

我尝试更改buttonPerfomed代码,但没有任何效果。

private void Button1ActionPerformed(java.awt.event.ActionEvent evt){

    if (AssessmentLearningColours2.answer.equals(Button1.getText())) {
        JOptionPane.showMessageDialog(null, "correct");
        check();
        count = 0;
    } else {
        JOptionPane.showMessageDialog(null, "incorrect");
        Button1.setEnabled(false);
        count++;

        if (count == 2) {
        count = 0;
         check();
    }

    }

}                                       

private void Button2ActionPerformed(java.awt.event.ActionEvent evt) {                                        

    if (AssessmentLearningColours2.answer.equals(Button2.getText())) {
        JOptionPane.showMessageDialog(null, "correct");
        check();
        count = 0;
    } else {
        JOptionPane.showMessageDialog(null, "incorrect");
        Button2.setEnabled(false);
        count++;

       if (count == 2) {
        count = 0;
         check();
    }

    }

}                                       

private void Button3ActionPerformed(java.awt.event.ActionEvent evt) {                                        

    if (AssessmentLearningColours2.answer.equals(Button3.getText())) {
        JOptionPane.showMessageDialog(null, "correct");
        check();
        count = 0;
    } else {
        JOptionPane.showMessageDialog(null, "incorrect");
        Button3.setEnabled(false);
        count++;

        if (count == 2) {
        count = 0;
         check();
    }

    }

}                                       

private void savebuttonActionPerformed(java.awt.event.ActionEvent evt) {                                           

    int returnVal = jFileChooser1.showOpenDialog(userInput.this);

    if (returnVal == jFileChooser1.APPROVE_OPTION) {

        File file = jFileChooser1.getSelectedFile();

        System.out.println("you are saving to" + file.getName());

    } else {
        System.out.println("saveing cancelled");
    }

}                                          

public void check(){

    Button1.setEnabled(true);
    Button2.setEnabled(true);
    Button3.setEnabled(true);
    String[] imagenames = {"black", "white", "green", "blue", "red", "brown", "orange", "yellow"};
    String[] maorinames = {"pangu", "ma", "kakariki", "kikorangi", "whero", "paraui", "karakaraka", "kowhai"};

    Random gen = new Random();
    int correct = gen.nextInt(8);

    Image nextColor = new ImageIcon(this.getClass().getResource(imagenames[correct] + ".png")).getImage();
    ImageIcon color = new ImageIcon(nextColor);

    color1.setIcon(color);

    if(englishButton.isSelected()== true){
         AssessmentLearningColours2.answer = imagenames[correct];

/ *生成一个随机数,该随机数将选择将以英语显示的颜色名称名称* /         布尔值检查= true;

    Button1.setText(imagenames[correct]);

    int incorrect = 99;

    while (checking) {
        incorrect = gen.nextInt(8);
        if (incorrect != correct) {
            checking = false;
            //stops the boolean from running 
        }
    }
    Button2.setText(imagenames[incorrect]);

    int incorrect2 = 99;
    checking = true;
    while (checking) {
        incorrect2 = gen.nextInt(8);
        if (incorrect2 != correct && incorrect2 != incorrect) {
            checking = false;
            //stops the boolean from running

        }
    }
    Button3.setText(imagenames[incorrect2]);

    }else{
        /* this code is for selecting the color names in maori */
         AssessmentLearningColours2.answer = maorinames[correct];
    boolean checking = true;

    Button1.setText(maorinames[correct]);

    int incorrect = 99;

    while (checking) {
        incorrect = gen.nextInt(8);
        if (incorrect != correct) {
            checking = false;
            //stops the boolean from running 
        }
    }
    Button2.setText(maorinames[incorrect]);

    int incorrect2 = 99;
    checking = true;
    while (checking) {
        incorrect2 = gen.nextInt(8);
        if (incorrect2 != correct && incorrect2 != incorrect) {
            checking = false;
            //stops the boolean from running

        }
    }
    Button3.setText(maorinames[incorrect2]);

    }

}

我希望得到的是我在图标下的jLabel属性中显示的简单彩色图像文件。

0 个答案:

没有答案