Event listener of image

shane5317's Avatar, Join Date: Mar 2011
Newbie Member
Hi all,
I am Beginner of Java.I having problems with the event listener. I have created image and successfully display on the screen. My problem is i don't have any ideas how to add the event listener onto image. Any tutorials?
For example,

JButton button = new JButton("click me");
button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e)
{
//Execute when button is pressed
JOptionPane.showMessageDialog(null,"You clicked the button");
}
});


How about image??I have image like this
Image img;
MediaTracker mt = new MediaTracker(this);
img = Toolkit.getDefaultToolkit().getImage("image1/Sleet.png");
mt.addImage(img,0);
//what should i do next

i want to perform just like button??can i do that?Anyone please help me!!
0
virxen's Avatar, Join Date: Nov 2009
Pro contributor
use a jlabel instead

http://www.kodejava.org/examples/402.html
0
shane5317's Avatar, Join Date: Mar 2011
Newbie Member
thanks so much. =D