java中如何修改代码中jLabel的图标?

How to change the icon of jLabel in code in java?

我正在尝试更改名为 "mainDot" 的 jLabel 的图标。我在源包中有另一个文件夹(名为 "Images"),其中包含我想要在按下时放在 mainDot 上的图标。

private void mainDotMousePressed(java.awt.event.MouseEvent evt) {                                     
    mainDot.setIcon(DOT_SMALL.jpg);
}

如何更改 mainDot 的图标?

public Test() {
    JLabel t=new JLabel();
    this.setLayout(new BorderLayout());
    t.setIcon(new ImageIcon("Path to image goes here"));
    this.add(t);
    this.pack();
    this.setVisible(true);  
}

这个正在运行。并按照建议使用动作侦听器在按下按钮时执行此操作