Event listener of image

Discussion in 'Java' started by shane5317, Mar 10, 2011.

  1. shane5317

    shane5317 New Member

    Joined:
    Mar 10, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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!!:embarasse
     
  2. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
  3. shane5317

    shane5317 New Member

    Joined:
    Mar 10, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    thanks so much. =D
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice