我想在点击后更改标签的图标图像
我在我的标签上添加了一个mouseListener并使用red_seat.jpg初始化
String seatImageUrl = "red_seat.jpg";
tempL = new JLabel(new ImageIcon(seatImageUrl));
tempL.addMouseListener(new seatMouseEvent());
在我的mouseListener类点击方法中,我有
public class seatMouseEvent implements MouseListener{
public void mouseClicked(MouseEvent e){
String seatImageUrl= "newImage.jpg";
try{
e.getComponent().setIcon(new ImageIcon(seatImageUrl)); //setIcon it's undefined
}
catch(Exception ex){
JOptionPane.showMessageDialog(null, "Error: " +ex.getMessage() );
}
}
}
答案 0 :(得分:0)
我必须使用演员
((JLabel)e.getComponent().)setIcon(new ImageIcon(seatImageUrl));