Question

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?

Was it helpful?

Solution

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}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top