ok.i have a problem in displaying the images into a jlabel.. the images is stored in mysql database and i used blob as its datatype.. my program is like a search engine.. when the user search for a keyword and click the search button it will show another class which contains the resulted images.. that is my problem..how to show the resulted images when the search button is click..here is my main class
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.BorderFactory.*;
import javax.swing.border.Border.*;
import javax.swing.border.TitledBorder.*;
import java.text.SimpleDateFormat;
//import java.sql.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.Graphics2D;
import java.io.InputStream;
public class Yeah extends JFrame implements ActionListener
{
ImageIcon icon = new ImageIcon();
String filename;
File file;
JFileChooser _fileChooser;
JLabel l1,l2,l3,l4,lph;
JLayeredPane lp1,lp2,lp3,lp4;
JPanel np,cp,sp,p,pp;
JButton searchb,uploadb;
JTextField txt1;
InputStream in,in1,in2;
BufferedImage bimg,bimg1,bimg2;
public Yeah()
{
JFrame frame=new JFrame("Yeah");
setSize(510,450);
l3 = new JLabel ("Search by keyword: ");
l4 = new JLabel ("or upload image");
_fileChooser = new JFileChooser();
lph = new JLabel();
l1 = new JLabel();
txt1 = new JTextField("Enter Keyword Here",10);
lp1 = new JLayeredPane();
lp2 = new JLayeredPane();
lp3 = new JLayeredPane();
lp4 = new JLayeredPane();
p = new JPanel();
np = new JPanel();
cp = new JPanel();
sp = new JPanel();
uploadb = new JButton("Upload");
uploadb.addActionListener(this);
lp3.setPreferredSize(new Dimension(150,20));
lp3.setLayout(new GridLayout(1,3,4,6));
lp3.add(uploadb);
searchb = new JButton("Search");
searchb.addActionListener(this);
lp3.setPreferredSize(new Dimension(150,20));
lp3.setLayout(new GridLayout(1,3,4,6));
lp3.add(searchb);
pp = new JPanel();
np.setLayout(new GridLayout(1,2));
lp1.setBorder(BorderFactory.createTitledBorder(""));
lp1.setPreferredSize(new Dimension(400,450));
lp1.setLayout(new GridLayout(9,1,4,6));
lp1.add(l3);
lp1.add(txt1);
lp1.add(l4);
lp1.add(uploadb);
lp1.add(searchb);
Font g=new Font("serif",1,20);
np.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"IMAGINE",javax.swing.border.TitledBorder.CENTER,javax.swing.border.TitledBorder.ABOVE_TOP,g,Color.red));
np.add(lp1);
lp2.setBorder(BorderFactory.createTitledBorder("Uploaded Photos"));
lp2.setPreferredSize(new Dimension(250,250));
lp2.setLayout(new GridLayout(1,0));
lp2.add(lph);
pp.add(lp2);
pp.add(lp3);
np.add(pp);
getContentPane().add(np,"North");
getContentPane().add(cp,"Center");
addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent we)
{
System.exit(0);
}
});
show();
}
public void actionPerformed(ActionEvent ae)
{
try
{
String str1= ae.getActionCommand();
if(str1.equals("Search"))
{
new yeahFrame();
}
if(str1.equals("Upload"))
{
int retval = _fileChooser.showOpenDialog(Yeah.this);
if(retval==JFileChooser.APPROVE_OPTION)
{
file = _fileChooser.getSelectedFile();
filename = file.getPath();
icon = new ImageIcon(filename);
lph.setIcon(icon);
}
}
}
catch (Exception e)
{
}
}
public static void main(String args[])
{
new Yeah();
}
}