开发者

How to add event for image

I want to add and event on image. That is, when I click on the image, it should be replaced with another image.

import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class RadioButtonLoader extends Canvas{

    private static final long serialVersionUID = 1L;
    BufferedImage image = null;
    public RadioButtonLoader(){
        try 开发者_开发百科{
            this.image = ImageIO.read(new File("res/rb1.gif"));

        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    public RadioButtonLoader(String checked){
        try {
            this.image = ImageIO.read(new File("res/rb2.gif"));

        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    @Override
    public void setSize(Dimension d) {
        super.setSize(new Dimension(15,22));
    }

    @Override
    public void paint(Graphics g) {
        setSize(new Dimension(15,22));
        g.drawImage(image, 0, 0, null);


    }   

}

How can I do it?


Simply you add mouselistner in your image in mouselister onclick method add your code...............

http://www.anyexample.com/programming/java/java_full_screen_image_viewer.xml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜