我写关于条件的代码,如果同一行中的按钮具有相同的图标图像,则弹出该操作的消息框。但是,如果我单击按钮,它将显示错误(线程“ AWT-EventQueue-0”中的异常java.lang.NullPointerException),并且操作未响应。 这是代码:
if(jButton3.getIcon().toString() == "resources/x-mark-300x300.png" && jButton2.getIcon().toString() == "resources/x-mark-300x300.png" && jButton1.getIcon().toString() == "resources/x-mark-300x300.png"){
JOptionPane.showMessageDialog(null,"Cie Menang !");
} else if(jButton3.getIcon().toString() == "resources/x-mark-300x300.png" && jButton5.getIcon().toString() == "resources/x-mark-300x300.png" && jButton7.getIcon().toString() == "resources/x-mark-300x300.png"){
JOptionPane.showMessageDialog(null,"Cie Menang !");
} else if(jButton3.getIcon().toString() == "resources/x-mark-300x300.png" && jButton6.getIcon().toString() == "resources/x-mark-300x300.png" && jButton9.getIcon().toString() == "resources/x-mark-300x300.png"){
JOptionPane.showMessageDialog(null,"Cie Menang !");
}