有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java标签检查图像

我有一些标签(10),我想在Label Image="pirosgomb.jpg"

我尝试了很多不同的方法,但都没能奏效

编辑:谢谢大家,现在开始工作,编辑代码:

if (event.getSource() instanceof JLabel) {
              kepstring=((JLabel)event.getSource()).getIcon().toString();

}

            if(kepstring.equals("pirosgomb.jpg")) {

            }else {

                if (x == 1) {
                    ((JLabel)event.getSource()).setIcon(new ImageIcon("zoldgomb.jpg"));
                    x = 2;

                } else if (x == 2) {
                    ((JLabel)event.getSource()).setIcon(new ImageIcon("sargagomb.jpg"));
                    x = 1;

                }
            }

共 (1) 个答案

  1. # 1 楼答案

    你想用^{}方法吗?e、 g:

    A1.setIcon(new ImageIcon("pirosgomb.jpg"))
    A1.setName("pirosgomb.jpg");
    
    if ("pirosgomb.jpg".equals(label.getName()) {
        label.removeMouseListener(this);
    }