Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果选择了两个切换按钮但不匹配,请将按钮设置回空白图像…Java Gui_Java_Swing_User Interface - Fatal编程技术网

如果选择了两个切换按钮但不匹配,请将按钮设置回空白图像…Java Gui

如果选择了两个切换按钮但不匹配,请将按钮设置回空白图像…Java Gui,java,swing,user-interface,Java,Swing,User Interface,使用切换按钮创建基本记忆游戏 private void tbtnCard3ActionPerformed(java.awt.event.ActionEvent evt) { tbtnCard3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Card3Logo.png"))); if(tbtnCard5.is

使用切换按钮创建基本记忆游戏

private void tbtnCard3ActionPerformed(java.awt.event.ActionEvent evt) {                                          
    tbtnCard3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Card3Logo.png")));
    if(tbtnCard5.isSelected()){
        score++;
        lblScore.setText(""+score);
    }
}                                         

private void tbtnCard4ActionPerformed(java.awt.event.ActionEvent evt) {                                          
     tbtnCard4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Card7EWaste.png")));
    if(tbtnCard7.isSelected()){
        score++;
        lblScore.setText(""+score);
    }
}                                         

private void tbtnCard5ActionPerformed(java.awt.event.ActionEvent evt) {                                          
     tbtnCard5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Card3Logo.png")));
    if(tbtnCard3.isSelected()){
        score++;
        lblScore.setText(""+score);
    }
}     
有更多的切换按钮,但我如何使它,如果两张卡被选中,他们不匹配设置为空或像一个空白图像。在此期间,我需要禁用所有其他按钮,以便在显示两个按钮时用户不能继续按下其他按钮。我不太确定如何才能让两个选定按钮上的图标先显示,然后返回空白图像,直到再次按下为止