问题
I'll make it short.
I've put a jLbl_show and in a if condition I've set an image for it.
if(int c==1){
jLbl_show0.setIcon(new ImageIcon(getClass().getResource("/img/wrong.png")));
}
else{
jLbl_show0.setIcon(new ImageIcon(getClass().getResource("/img/ok.png")));
}
But, as now the image is set i need to take the image URL to another condition. which is like;
if(imageURL is "/img/ok.png"){ do somthing }
elseif (imgURL is "/img/wrong.png"){ do something }
is there a way to do this?
回答1:
do something like this:
boolean flag = false;
if(someBoolean){
jLbl_show0.setIcon(new ImageIcon(getClass().getResource("/img/wrong.png")));
flag = true;
}
else{
jLbl_show0.setIcon(new ImageIcon(getClass().getResource("/img/ok.png")));
}
if(flag){something}
else{something}
来源:https://stackoverflow.com/questions/13188874/getting-jlabel-image-url-in-java