
Hi, I have some requireemnt like when i click on the button in frame,it wil display the image.....plz do the needful.............

import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
public class DisplayImage {
JFrame f;
JButton browse;
JLabel label;
File file = null;
public DisplayImage() {
f = new JFrame("");
browse = new JButton("Display");
label=new JLabel();
browse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.addChoosableFileFilter(new ImageFileFilter());
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile();
String path=file.getPath();
ImageIcon myIcon = new ImageIcon(path);
label.setIcon(myIcon);
f.repaint();
}
}
});
f.setLayout(null);
browse.setBounds(10,20,100,20);
label.setBounds(10,40,350,300);
f.add(browse);
f.add(label);
f.setSize(350, 320);
f.setVisible(true);
}
public static void main(String[] args) {
new DisplayImage();
}
}
class ImageFileFilter extends javax.swing.filechooser.FileFilter {
public boolean accept(File file) {
if (file.isDirectory()) return false;
String name = file.getName().toLowerCase();
return (name.endsWith(".jpg") || name.endsWith(".png")|| name.endsWith(".gif"));
}
public String getDescription() { return "Images (*.gif,*.bmp, *.jpg, *.png )"; }
}