在Java中获取jLabel图像URL [英] Getting jLabel image url in Java
本文介绍了在Java中获取jLabel图像URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我会简短点
我放置了一个jLbl_show,并在if条件下为其设置了图像.
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?
推荐答案
执行以下操作:
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}
这篇关于在Java中获取jLabel图像URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文